306 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Exclusive Author
  • Microlancer Beta Tester
  • United States
  • Has been a member for 4-5 years
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
brainbuzzmedia says

I have options for the 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/'
        });
    });
</script>

My problem is, I need to put wp_head() directly before the closing < /head> tag as that is a requirement now 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’m sure there is an obvious way to do this but I can’t seem to figure it out. Can anyone give me a hand?

69 posts
  • Microlancer Beta Tester
  • Most Wanted Bounty Winner
  • Exclusive Author
  • Referred between 1 and 9 users
  • Has been a member for 2-3 years
AlphaPixels says

I can’t understand what are you trying to say BUT I can see that your script is executed after the jquery is loaded because it’s inside the jquery wrapper function . :)

3007 posts
  • Author had a File in an Envato Bundle
  • Bought between 1 and 9 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 100 and 199 users
+2 more
duotive says
Why not using a hook.
add_action('wp_head', 'slideshowSettings');
function slideshowSettings () {
$code = ........
............
echo $code;
}

PHP will always get executed before javascript. Server side versus client side.

3007 posts
  • Author had a File in an Envato Bundle
  • Bought between 1 and 9 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 100 and 199 users
+2 more
duotive says

And your call does not have document ready. I am not that good with jquery, but isn’t’ that needed?

331 posts
  • Exclusive Author
  • Sold between 5 000 and 10 000 dollars
  • Has been a member for 4-5 years
  • Europe
  • Microlancer Beta Tester
  • Bought between 1 and 9 items
  • Referred between 1 and 9 users
dekciw says

And your call does not have document ready. I am not that good with jquery, but isn’t’ that needed?
jQuery(function(){ ... cool stuff in here ... });
Can be done instead of document ready :)
306 posts
  • Elite Author
  • Sold between 100 000 and 250 000 dollars
  • Exclusive Author
  • Microlancer Beta Tester
  • United States
  • Has been a member for 4-5 years
  • Bought between 10 and 49 items
  • Referred between 1 and 9 users
brainbuzzmedia says

Hmmmmm yes it does work to use your method Duotive but the variables don’t pass. Any idea how to do that?

707 posts
  • Sold between 10 000 and 50 000 dollars
  • Referred between 10 and 49 users
  • Bought between 10 and 49 items
  • Has been a member for 5-6 years
  • Exclusive Author
  • Microlancer Beta Tester
ChillThemes says

Check out wp_localize_script. Here’s a blog post going over adding PHP variables to your scripts.

3007 posts
  • Author had a File in an Envato Bundle
  • Bought between 1 and 9 items
  • Elite Author
  • Europe
  • Exclusive Author
  • Has been a member for 3-4 years
  • Referred between 100 and 199 users
+2 more
duotive says

Get them inside the function :)

by
by
by
by
by
by