0

I have bought a theme, but on a particular page i don't want to use the theme js/css files.

The theme registers the files like

function add_our_scripts() {
    global $post;

    $options = get_option('radium_theme');

    wp_enqueue_style( 'radium', RADIUM_CSS_URL . '/radium.css', false,'1.0','all'); //the framework stylesheet
    wp_enqueue_style( 'main-style', get_stylesheet_uri(), false,'1.0','all'); //the main stylesheet
    wp_enqueue_style('sliders', RADIUM_CSS_URL . '/sliders.css',false,'1.0','all'); //sliders
    wp_enqueue_style etc

and add_action call

add_action( 'wp_enqueue_scripts', 'add_our_scripts',0);

full js http://jsfiddle.net/wesweatyoushop/FQrKp/

I created the following remove function

    function remove_radium_scripts() {
    echo 'Test check';
    wp_dequeue_style('radium');
    //wp_dequeue_style( array('radiumshortcodes','sliders','radium') );
    //wp_deregister_style( array('radiumshortcodes','sliders','radium') );
}

add_action( 'test_remove_scripts', 'remove_radium_scripts', 999 );

And in the header of the specific page i added

do_action('test_remove_scripts');

I can see the Test check but the radium.css is still there

How can i fix this

4
  • We need a bit more code in order to answer your question. What is the add_action() call into which add_our_scripts() is hooked? Oct 29, 2013 at 13:12
  • @ChipBennett fyi add_action( 'wp_enqueue_scripts', 'add_our_scripts',0); and i already tried wp_dequeue_script('radium');
    – alex
    Oct 29, 2013 at 13:21
  • please edit your question to add this detail, so it doesn't get lost in the comments. Oct 29, 2013 at 13:51
  • Or, you can add some direct condition with "page id" to skip files that you don't want.
    – Romain
    Oct 29, 2013 at 14:16

2 Answers 2

2

Use the correct action hook

Notice the action hook being used:

add_action( 'wp_enqueue_scripts', 'add_our_scripts',0);

And the action hook you're defining/using:

add_action( 'test_remove_scripts', 'remove_radium_scripts', 999 );

You need to hook into the same action:

add_action( 'wp_enqueue_scripts', 'remove_radium_scripts', 999 );

Use the correct priority

Notice the priority being used:

add_action( 'wp_enqueue_scripts', 'add_our_scripts',0);

And the priority you're using:

add_action( 'wp_enqueue_scripts', 'remove_radium_scripts', 999 );

You need to hook into the same priority:

add_action( 'wp_enqueue_scripts', 'remove_radium_scripts', 0 );

If all else fails, use last-minute dequeue

If those don't work, you can use a more aggressive option: dequeue at wp_print_styles, with a high priority:

add_action( 'wp_print_styles', 'remove_radium_scripts', 9999 );
1
  • thanks i tried your suggestion with no luck. Not even the following in functions.php function remove_radium_scripts() { echo 'Remove it?: '.time(); wp_dequeue_script('radium'); } //add_action( 'wp_enqueue_scripts', 'remove_radium_scripts', 0 ); add_action( 'wp_print_styles', 'remove_radium_scripts', 9999 );
    – alex
    Oct 30, 2013 at 9:22
0

All you need to dequeue that stylesheet is:

function remove_radium_scripts() {
    wp_dequeue_style('radium');
    //wp_dequeue_style( array('radiumshortcodes','sliders','radium') );
    //wp_deregister_style( array('radiumshortcodes','sliders','radium') );
}
add_action( 'wp_enqueue_scripts', 'remove_radium_scripts', 999 );

I don't know exactly where you've added that new action but it is almost certainly going to be too early or too late. Before wp_head() is too early, after is too late. You'd have to add your hook on a hook to make that work. Something like this (before wp_head()).

add_action(
  'wp_head',
  function() {
    do_action('test_remove_scripts'); 
  },
  1,999
);
9
  • Why create an action hook just to hook it into an existing action? Oct 29, 2013 at 14:39
  • @ChipBennett: Look at the first block of code. That is the solution. The second block is part of the explanation of why the OP's code does not work and what you'd have to do to make it work.
    – s_ha_dum
    Oct 29, 2013 at 14:59
  • I understand that the OP created a new action hook. I disagree that such is needed, preferable, or even recommended. Oct 29, 2013 at 15:11
  • @ChipBennett: Look at the first block of code-- the block labeled "All you need to dequeue that stylesheet is:" What part of that are you missing?
    – s_ha_dum
    Oct 29, 2013 at 15:12
  • Maybe we're saying the same thing? Oct 29, 2013 at 15:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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