498 posts
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
wopethemes says
hi
as themeforest require load scripts from wp_head . and the wp_head must be immediately </head>
so how can I call a function with options from php?
I can’t call this function inside the script.js to load from wp_head. I must place this function below the wp_head because I can get jquery work after wp_head loaded
jQuery(document).ready(function(){
            //call slider
            jQuery('#main-slider').wopeslider({
                'height': 960,
                'width' : <?php echo empty($slider_options['slider_height']) ? 400 : $slider_options['slider_height'] ;?>
            });
...
});
1509 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+2 more
OriginalEXE says

I am not sure what the problem is, but you don’t have to manually echo php variables, use wp_enqueue_script to enqueue script.js, make sure it’s dependency is set to jquery, and then use this function: http://codex.wordpress.org/Function_Reference/wp_localize_script

498 posts
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
wopethemes says

maybe you’re right , let me try it.

203 posts
  • Has sold $40,000+ on Envato Market
  • Made it to the Authors' Hall of Fame
  • Contributed a free file of the month
  • Has been part of the Envato Community for over 2 years
+2 more
ikaruna says

maybe you’re right , let me try it.

he is definitely right, otherwise you will get rejected, and worse – different problems might show up on different systems, also don’t forget to enqueue script specifying which lib the script depends on.

cheers!

498 posts
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
wopethemes says


maybe you’re right , let me try it.

he is definitely right, otherwise you will get rejected, and worse – different problems might show up on different systems, also don’t forget to enqueue script specifying which lib the script depends on.

cheers!

thanks!
I call javascript below the html blocks :D

161 posts
  • Has sold $10,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Has been part of the Envato Community for over 2 years
  • Sells items exclusively on Envato Market
themebros says

Or you can go with this:

add_action( 'wp_head', 'yourprefix_head_js' );
function yourprefix_head_js(){
    ?>
         <script type="text/javascript">
             /* The JavaSript */
         </script>
    <?php
}
1179 posts
  • Has referred 200+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
mabuc says

try this..

function slider() {

<script type="text/javascript">    
jQuery(document).ready(function(){
            //call slider
            jQuery('#main-slider').wopeslider({
                'height': 960,
                'width' : <?php echo empty($slider_options['slider_height']) ? 400 : $slider_options['slider_height'] ;?>
            });
...
});
</script> 

}

add_action( 'wp_head', 'slider' );
161 posts
  • Has sold $10,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Has been part of the Envato Community for over 2 years
  • Sells items exclusively on Envato Market
themebros says

@mabuc

Always add a prefix.

Prefix everything

And $slider_options doesn’t exists in there, needs to be defined at the top of the function first.

498 posts
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
wopethemes says

thanks bros for suggestions :D

161 posts
  • Has sold $10,000+ on Envato Market
  • Has collected 1+ items on Envato Market
  • Has been part of the Envato Community for over 2 years
  • Sells items exclusively on Envato Market
themebros says

thanks bros for suggestions :D

You’re welcome :)

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