Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

There is a theme my client is using. It enqueues many scripts in the admin area of wordpress. I'd like to dequeue these so that my plugin works properly.

Commenting out this code wp_enqueue_script( "ocmx-jquery", get_template_directory_uri()."/scripts/ocmx.js", array( "jquery" ) ); makes my plugin work properly. So rather than edit their code, I want to add the following to my plugin wp_dequeue_script( 'ocmx-jquery' );. I've added that, and it's as if I never did.

Is there a better way to tell the theme's JS not to load in my plugins settings page?

share|improve this question
    
possible duplicate of How to solve a conflict between a plugin and a theme? –  brasofilo Oct 7 '13 at 1:07
    
I tried the solution from that page, and it didn't work. The page still functioned as though I didn't have the code in place. –  Branndon Oct 7 '13 at 2:30
    
@Branndon You'll have to use the appropriate hooks. admin_head, admin_print_scripts, admin_enqueue_scripts, etc. Please show us in an edit how exactly your tried to get rid of that script. What you should as well do is notifying those guys who developed that theme that it's complete crap! to do that. –  kaiser Oct 26 '13 at 23:24

2 Answers 2

You need to dequeue after the other script has been enqueued. That probably means hooking into wp-enqueue_scripts.

add_action(
  'wp_enqueue_scripts',
  function() {
    wp_dequeue_script( 'ocmx-jquery' );
  }
);

Or a version for an older PHP:

function dequeue_ocmx_jquery() {
    wp_dequeue_script( 'ocmx-jquery' );
}
add_action(
  'wp_enqueue_scripts',
  'dequeue_ocmx_jquery'
);
share|improve this answer
    
Tried this, doesn't work. It's at the top of my options page, and now the page won't even load. If I remove this code, the page loads again. –  Branndon Oct 7 '13 at 2:23
    
This should not really go at the top of your options page. Try the other version –  s_ha_dum Oct 7 '13 at 2:55
    
Thanks @s_ha_dum the second didn't work either. I didn't want to dequeue their script globally, only on my settings page. That's why I put it in my options page code. If I just put the code in the main admin area, it would stop their code from running anywhere, and I didn't want to do that. –  Branndon Oct 7 '13 at 16:09
    
Try admin_enqueue_scripts instead of wp_enqueue_scripts. I didn't realize this was a backend problem. However, depending on where that plugin has its code, you may not be able to get rid of it. –  s_ha_dum Oct 7 '13 at 16:11

http://codex.wordpress.org/Function_Reference/wp_dequeue_script

Have a look especially at the bottom of the page, i think this is what you want : "Admin: admin_enqueue_scripts, admin_print_scripts, admin_print_styles"

share|improve this answer
    
Please explain how to use wp_dequeue_script() and what exactly those hooks do and how to use them. Please also care a bit about the formatting of your question. Hint: The WYSIWYG editor got a (?) help link and something to format links and code segments. Have fun on the site :) –  kaiser Oct 26 '13 at 23:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.