I have settings for an image slider in my wordpress admin panel that lets you change things such as the transition effect and speed, etc. These settings (php variables) are passed to the standard initialization script for the slider which looks like this:
<script>
jQuery(function(){
jQuery('#camera_wrap_3').camera({
height: '40%',
thumbnails: true,
time: <?php echo $pause_time; ?>,
fx: '<?php echo $transition_effect; ?>',
transPeriod: <?php echo $transition_speed; ?>,
autoAdvance: <?php echo $auto_advance; ?>,
minHeight: '50px',
mobileNavHover: false,
imagePath: '<?php echo get_template_directory_uri(); ?>/images/'
});
});
I choose to save this as a separate php file to clean up the code.
My problem is, I need to put wp_head() directly before the closing < /head> tag and when I do this there is no way to implement the above script AFTER jQuery is loaded and therefor it does not work and the slider doesn’t work either.
I have tried attaching it with an action hook like I would with a js file like so:
<?php function add_camera_init() {
require_once('includes/sliders/camera/camera-init.php');
}
add_action('wp_enqueue_scripts', 'add_camera_init'); ?>
but this didn’t seem to do anything.
How can I add settings like this after jQuery and still have wp_head() immediately before < /head>?
Try
add_action('wp_print_footer_scripts','add_camera_init');