1097 posts
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
+6 more
greenline says

Hi, as I am not so good with WordPress themes, I really need some help.

I am a codecanyon author and one of my plugins work in general with any theme.
But …with some themes, the plugin is not working, because the scripts does not load.

So, the question: where I should look in a theme to find why it does not load plugins scripts – nor in the header, nor in the footer? The wp_head() and wp_footer() are there, at their place in the theme.

If I manually place the plugins scripts in the theme’s header.php file, before the /HEAD tag, the plugin works, otherwise, it doesn’t.

I am sure it’s related to the themes, because with the best-sellers themes works. So I am sure it has something to with the way themes load scripts.

EDIT: I forgot to mention I load the scripts in my plugin the normal way, using
wp_enqueue_script('responsive_xxxxx', false);
1276 posts
  • Has been part of the Envato Community for over 4 years
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
+5 more
Smartik says
It’s hard to give a solution without the real code, but make sure that you enqueue the script in the right way. Also try to set a priority
function my_scripts_method() {
    wp_enqueue_script( 'script_name' );
}
add_action( 'wp_enqueue_scripts', 'my_scripts_method', 50 );//50 is the priority
123 posts
  • Has referred 50+ members
  • Has sold $125,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 100+ items on Envato Market
+5 more
nagaemas says

Most likely the theme in question doesn’t have wp_footer or wp_head in their code. If so, it’s not your mistake :)

1055 posts Best-dressed man at PressNomics 2013
  • Has sold $1M+ on Envato Market and is now a Power Elite Author
  • Power Elite Author: Sold more than $1M on Envato Market
  • Made it to the Authors' Hall of Fame
  • Had an item featured on Envato Market
+10 more
Parallelus says

Most likely the theme in question doesn’t have wp_footer or wp_head in their code. If so, it’s not your mistake :)

Does that really still happen? I haven’t seen a theme missing either of those functions in years. I’m not even sure a theme will work without wp_head in the current version of WP. I’ve never had a reason to try it though.

3497 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $750,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 more
sevenspark Moderator says


Most likely the theme in question doesn’t have wp_footer or wp_head in their code. If so, it’s not your mistake :)
Does that really still happen? I haven’t seen a theme missing either of those functions in years. I’m not even sure a theme will work without wp_head in the current version of WP. I’ve never had a reason to try it though.

Sadly, this does still happen, I see it more frequently than you would expect. Most of the time it is a customer who has had a “custom” theme created, but I do see it on commercial themes as well. I haven’t seen this in a ThemeForest theme for a while, though.

Though, I think @greenline is saying that those hooks are actually present.

@greenline, what is the exact code you are using? Are you sure it is executed (try a print statement)? Perhaps something is breaking the logic prior to your wp_enqueue_script call.

Also, is the customer using a caching plugin? If the script doesn’t seem to be present, it may have been minified/concatenated and not running due to a separate javascript error.

1097 posts
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
+6 more
greenline says

Thank you all for your help.

The customer has indeed a custom theme, created based on http://underscores.me/
I just checked, now his custom theme has wp_head() and wp_footer() in the correct place.
And now my jquery scripts are loading, but inside the BODY tag, when they should in fact be loaded inside the head.
Which seems to be the problem, the plugin works with this theme only if I manually put the plugins jquery scripts inside the HEAD tag in header.php file of the theme.

(this is usually happening with custom themes, not with the ones from themeforest. With themeforest themes, everything is working just fine – that is why I asked here – my guess is that theme, like other custom themes, is doing something different then TF themes and I don’t know what…)

1097 posts
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
+6 more
greenline says

To be more specific, my plugin used with this theme generates a code like this:

< body >
...

<script type="text/javascript">
    jQuery(document).ready(function($) {
           mapdiv.gMap({
               // some code here
</script>
<script type='text/javascript' src='..js/jquery.gmap.min.js?ver=3.3.3'></script>

...
</ body >

In this theme, the code does not execute, it says in the developer console that “gMap” is not a function, meaning that it does not recognize the jquery.gmap.min.js script, because it is not loaded in the head.

With themeforest themes, I do not have this problem :)

And no, the customer does not have any caching plugin.

3 posts
  • Has been part of the Envato Community for over 2 years
  • Sells items exclusively on Envato Market
SowAd says

Have you called the function using the wp_enqueue_scripts action hook as Smartik mentioned above? Something like this should work:

function my_scripts_method() {
    wp_enqueue_script(
        'script_name',
        plugins_url( '/js/jquery.gmap.min.js' , __FILE__ ),
        array( 'jquery' ),
        '3.3.3',
        false // it's the default value
    );
}

add_action( 'wp_enqueue_scripts', 'my_scripts_method' );
3497 posts
  • Elite Author: Sold more than $75,000 on Envato Market
  • Has sold $750,000+ on Envato Market
  • Located in United States
  • Helps us moderate the forums
+10 more
sevenspark Moderator says

Unless the customer removed functionality from the underscores theme, that’s pretty surprising – Underscores is the best starter theme out there in my opinion.

Except in very specific circumstances, you should be loading your javascript in the footer rather than the header anyway.

You should also be registering the gmap script as a dependency of your own script, to ensure it is loaded before yours.

It’d still be good to see your actual code, as well as a link to the site, so we can actually troubleshoot rather than just shooting in the dark :P

1097 posts
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 50+ items on Envato Market
  • Sells items exclusively on Envato Market
+6 more
greenline says

Just a short update, hoping it will help others shooting in the dark for three days like me :)

(I couldn’t post link to the website, I did not had the customer’s permission)

I discovered that a blank new theme based on underscores does not have jquery support by default. So, the customer, created his own jquery file (deprecated, 1.3 version) and then included this file in his header.php file, before the ending HEAD tag).

I told him that this is not correct and that, instead, he should add the following snippet in theme’s functions.php to add jQuery support to his theme:

/**
 * Add jquery support
 */
function jquery_scripts() {
     wp_enqueue_script( 'jquery' );
}
add_action( 'wp_enqueue_scripts', 'jquery_scripts' );

So, thank you customers, I learn every day something new :)
Now it works :)

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