• My assumption is that I’m dealing with customizer stuff, and variable passing, but I’ve searched for different combinations and haven’t had luck finding the right info.

    Here’s what I’d like to accomplish:

    I have a simple slideshow set up using Advanced Custom Fields to get the images & captions. I have a JS file that injects settings (transition time, etc.) into the main slider script. I’d like to add a way to change the slider settings via the admin. Much like you can change site title & description in the customizer.

    Not looking for a total solution, just a point in the right general direction in the Codex maybe. Not sure where to start.

    Thanks!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter Greg Smith

    (@elmnt)

    OK, I’ve figured out most of this. I think the rest of my solution is to involve the ACF variables. I’ll add more info if I resolve it, maybe this will help someone else searching for similar info.

    // in functions.php
    
    	// enqueue my script (and the settings script)
    	wp_enqueue_script( 'my-slider', get_template_directory_uri() . '/js/responsiveslides.js', array(), '20150311', true );
    	wp_enqueue_script( 'my-slider-settings', get_template_directory_uri() . '/js/responsiveslides-settings.js', array('my-slider'), '20150311', true );
    
    	// localize my settings script to pass variables into PHP
    	$params = array(
    	    'auto' => true,
    	    'speed' => 500,
    	    'timeout' => 1000
    	);
    	wp_localize_script( 'my-slider-settings', 'mysliderparams', $params );
    
    	// And in responsiveslides-settings.js
    
    	(function($){
    
    	    $("#slider").responsiveSlides({
    	      auto: mysliderparams.auto,
    	      speed: mysliderparams.speed,
    	      timeout: mysliderparams.timeout
    	    });
    
    	})(jQuery);
    Thread Starter Greg Smith

    (@elmnt)

    I was able to get it working with this one modification:

    $timeoutvar = get_field('slideshow_timeout');
    
    	$params = array(
    	    'auto' => true,
    	    'speed' => 500,
    	    'timeout' => $timeoutvar
    	);

    I just access my ACF name and set it as a variable.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Customize javascript settings via admin?’ is closed to new replies.