1486 posts
  • Trendsetter
  • Most Wanted Winner
  • Author Level 5
  • Collector Level 3
+8 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);
1368 posts
  • Weekly Top Seller
  • 5 Years of Membership
  • Author Level 6
  • Beta Tester
+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
252 posts
  • Elite Author
  • Author Level 8
  • Weekly Top Seller
  • Trendsetter
+7 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 :)

1095 posts Best-dressed man at PressNomics 2013
  • Power Elite Author
  • Author Level 12
  • Featured Author
  • Featured Item
+13 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.

3535 posts
  • Power Elite Author
  • Author Level 12
  • Trendsetter
  • United States
+13 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.

1486 posts
  • Trendsetter
  • Most Wanted Winner
  • Author Level 5
  • Collector Level 3
+8 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…)

1486 posts
  • Trendsetter
  • Most Wanted Winner
  • Author Level 5
  • Collector Level 3
+8 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
  • 3 Years of Membership
  • Exclusive Author
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' );
3535 posts
  • Power Elite Author
  • Author Level 12
  • Trendsetter
  • United States
+13 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

1486 posts
  • Trendsetter
  • Most Wanted Winner
  • Author Level 5
  • Collector Level 3
+8 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 :)

by
by
by
by
by
by