I have a buyer, he uses a free template from template-help.com.
The wp_enqueue_script call which I use in one of my plugins does not execute when the plugin is used with themes downloaded from template-help.com
Anyone experienced that before?
I have a buyer, he uses a free template from template-help.com.
The wp_enqueue_script call which I use in one of my plugins does not execute when the plugin is used with themes downloaded from template-help.com
Anyone experienced that before?
Assuming you attached your wp_enqueue_script() call to the right action hook, the theme probably forgot to include wp_head() or wp_footer() in its header.php and/or footer.php. In that case the action to print header/footer scripts would never be called.
This is how I call wp_enqueue_script():
/** * Register plugin's javascript */ function my_scripts() { wp_register_script('myplugin', plugins_url('includes/myplugin.js', __FILE__), '1,0'); } add_action('wp_enqueue_scripts', 'my_scripts'); /** * Define the shortcode and its attributes */ function myshortcode($atts) { // Enqueue jquery script and plugin's script wp_enqueue_script("jquery"); wp_enqueue_script('myplugin'); .... }
EDIT: I removed from the code any reference to my plugin’s name.
Check if “wp_print_scripts” works?
Thanks, I will try. The problem is, the customer is a beginner without programming knowledge and he also does not give me admin access Nice as always. And, of course - the issue appears on the live website.
sevenspark saidthis solved all the similar problems I add from clients.Assuming you attached your wp_enqueue_script() call to the right action hook, the theme probably forgot to include wp_head() or wp_footer() in its header.php and/or footer.php. In that case the action to print header/footer scripts would never be called.
If he can’t add this lines of code himself, and doesn’t give you admin access… then… not much more you can do
I tried to modify your code above, please try this if needed
/** * Register plugin's javascript */ function my_scripts() { wp_register_script('myplugin', plugins_url('includes/myplugin.js', __FILE__), array( 'jquery' ), '1.0', true); } add_action('wp_enqueue_scripts', 'my_scripts'); /** * Define the shortcode and its attributes */ function myshortcode($atts) { // Enqueue jquery script and plugin's script wp_enqueue_script('myplugin'); .... }
Your javascript requires jquery, so I put the $deps=array(‘jquery’)
on the dependency list, and no need to call jquery again on your shortcode. Then i put $in_footer=true
to make sure that your javascript will be executed on footer. This is a better approach.
greenline saidThanks, I will try. The problem is, the customer is a beginner without programming knowledge and he also does not give me admin access
Nice as always. And, of course - the issue appears on the live website.
No need to be a developer to do this. I always try to give simple explanation for this type of buyer. The point is, they need to check it by himself. You can start making a standard answer for this.
For example:
I believe that something wrong with your free theme. If you want to use free theme, I recommend you to download it from official WordPress repository, WordPress Theme Directory | WordPress.org because it follows all WordPress standard and already checked by WordPress reviewer.
If you want to help me to check, you can go to Appearance - Editor, and click header.php
on the left to edit this file and search wp_head
. Then click footer.php
on the left to edit this file and search wp_footer
. If you can’t find it, it means that your theme is not standard and the theme developer has to fix it.
Thank you so much PrimaThemes! Such a detailed and helpful answer!
I will make these changes in the following version of my plugin too.
We just got it sorted out after about 5 hours of emails & debugging together - it turned out that functions.php and header.php from the free theme had some errors.
Pffff I have 10 years experience as Java&web developer … PHP still has some secrets for me I like your approach about free themes
I never knew how to tell people that free themes have bugs without offending them.
Thank you guys for your help.
Another happy customer, time to go to sleep.