308 posts
  • Has referred 1+ members
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+4 more
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
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Won a Most Wanted contest
  • Sells items exclusively on Envato Market
+1 more
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
  • Has been part of the Envato Community for over 4 years
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Had an item featured in an Envato Bundle
+7 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
  • Has been part of the Envato Community for over 4 years
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Had an item featured in an Envato Bundle
+7 more
duotive says

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

332 posts
  • Has referred 1+ members
  • Has sold $5,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 1+ items on Envato Market
+2 more
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 :)
308 posts
  • Has referred 1+ members
  • Has sold $75,000+ on Envato Market and is now an Elite Author
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+4 more
brainbuzzmedia says

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

709 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+2 more
ChillThemes says

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

3007 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 200+ members
  • Has sold $250,000+ on Envato Market
  • Had an item featured in an Envato Bundle
+7 more
duotive says

Get them inside the function :)

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by