• 1.
    // Declare variables
  • 2.
    $imageArray = array();
  • 3.
    if(get_field('image_container')) {
  • 4.
    	while(the_repeater_field('image_container')) {
  • 5.
    		$imageSource = wp_get_attachment_image_src(get_sub_field('image'), 'full');
  • 6.
    		$thumbSource = wp_get_attachment_image_src(get_sub_field('image'), 'background_thumb');
  • 7.
    		array_push($imageArray,"{image : '" . $imageSource[0] . "', thumb : '" . $thumbSource[0] . "'}");
  • 8.
    	}
  • 9.
    }
  • 10.
     
  • 11.
    $imageOutput = json_encode($imageArray);
  • 12.
    		
  • 13.
    // Add some parameters for the JS.
  • 14.
    wp_localize_script(
  • 15.
    	'shutter_home',
  • 16.
    	'shutter',
  • 17.
    	array(
  • 18.
    		'imageOutputjs' => $imageOutput
  • 19.
    	)
  • 20.
    );
  • 21.
     
  • 22.
     
  • 23.
     
  • 24.
     
  • 25.
    // What is outputting in my HTML
  • 26.
    <script type='text/javascript'>
  • 27.
    /* <![CDATA[ */
  • 28.
    var shutter = {"imageOutputjs":"[\"{image : '\\\/phopaws\\\/assets\\\/0009.jpg', thumb : '\\\/phopaws\\\/assets\\\/0009-150x100.jpg'}\",\"{image : '\\\/phopaws\\\/assets\\\/DSC_2454_bw_Gracey.jpg', thumb : '\\\/phopaws\\\/assets\\\/DSC_2454_bw_Gracey-150x100.jpg'}\"]"};
  • 29.
    /* ]]> */
  • 30.
    </script>
  • 31.
     
  • 32.
     
  • 33.
    // Currently tried calling it in my shutter-home.js as such without luck
  • 34.
     
  • 35.
    slides : [										$.parseJSON(shutter.imageOutputjs.replace('&quot;', '"');
  • 36.
    									],
// Declare variables $imageArray = array(); if(get_field('image_container')) { while(the_repeater_field('image_container')) { $imageSource = wp_get_attachment_image_src(get_sub_field('image'), 'full'); $thumbSource = wp_get_attachment_image_src(get_sub_field('image'), 'background_thumb'); array_push($imageArray,"{image : '" . $imageSource[0] . "', thumb : '" . $thumbSource[0] . "'}"); } } $imageOutput = json_encode($imageArray); // Add some parameters for the JS. wp_localize_script( 'shutter_home', 'shutter', array( 'imageOutputjs' => $imageOutput ) ); // What is outputting in my HTML <script type='text/javascript'> /* <![CDATA[ */ var shutter = {"imageOutputjs":"[\"{image : '\\\/phopaws\\\/assets\\\/0009.jpg', thumb : '\\\/phopaws\\\/assets\\\/0009-150x100.jpg'}\",\"{image : '\\\/phopaws\\\/assets\\\/DSC_2454_bw_Gracey.jpg', thumb : '\\\/phopaws\\\/assets\\\/DSC_2454_bw_Gracey-150x100.jpg'}\"]"}; /* ]]> */ </script> // Currently tried calling it in my shutter-home.js as such without luck slides : [ $.parseJSON(shutter.imageOutputjs.replace('&quot;', '"'); ],

Copy Code to Clipboard Raw

Sign-in or Create a Free Account.

Snippi uses Twitter or Facebook to register and create accounts. Registration will enable you to keep track of your snippets. We never spam your timeline or wall. Ever.

Sign-in with Facebook Sign-in with Twitter