0

In my theme there is the following code (that is printing some inline css on the head of my site)

final class Design_Scheme {



/**
 * Design_Scheme constructor.
 */
private function __construct() {
    $this->hooks();
}



/**
 * Setup Hooks
 */
public function hooks() {
    add_action( 'wp_enqueue_scripts', array( $this, 'header_style_css' ), 11 );
    add_action( 'wp_enqueue_scripts', array( $this, 'footer_style_css' ), 11 );
    add_action( 'wp_enqueue_scripts', array( $this, 'global_style_css' ), 11 );
    add_action( 'wp_enqueue_scripts', array( $this, 'badges_style_css' ), 11 );
    add_action( 'wp_head', array( $this, 'set_mobile_address_bar_color' ) );
}

public function header_style_css() { ... 
public function footer_style_css() { ...

}

and i have been trying to Dequeue some styles from the hook but with no success. I have tried everything, but doesn't work.

function remove_inline_style(){
if ( is_page( 'live' ) ){
wp_dequeue_script('header_style_css');
wp_deregister_style('header_style_css');
   }
}
add_action( 'wp_enqueue_scripts', 'remove_inline_style', 999 );
add_action( 'wp_head', 'remove_inline_style', 999  );
add_action( 'wp_print_styles', 'remove_inline_style', 999 );
add_action( 'init', 'remove_inline_style', 999 );

Any help or ideas what i am doing wrong?

Thank you

11
  • Last part of your code from functions.php?
    – anton
    May 18, 2021 at 10:42
  • are you sure that header_style_css is the name of the style, and not the name of the function the theme uses? The code in your question is incomplete, and the order that hooks run in is important ( you can't dequeue a script before it's been enqueued ). Also, where is your code located?
    – Tom J Nowell
    May 18, 2021 at 10:43
  • @TomJNowell you can see the full php file that make use of the css here pastebin.com/j94PSUAX . I am not sure where should i look . In the html is printed <style id='theme-primary-style-inline-css' type='text/css'> . Tried to use theme-primary-style-inline-css but it seems its not the handler. The files name is design-scheme.php and the path of the file \wp-content\themes\mytheme\includes\front\design-scheme.php May 18, 2021 at 12:06
  • 1
    Ok so dequeueing is the wrong word/phrase to use as you do not want to dequeue the main stylesheet, you want to prevent the inline CSS being added. You should unhook the actions that add the inline styling instead. Have you contacted the theme author/provider?
    – Tom J Nowell
    May 18, 2021 at 18:17
  • 1
    @Honoluluman, that header_style_css() function is not a global function; it's a class method, so when using it with remove_action(), you need to use the object method (more details here), e.g. array( $object, 'method' ). And in your case, that object is Design_Scheme::get_instance() - see at the very bottom here. Also, note that we dequeue a CSS file using wp_dequeue_style() and not wp_dequeue_script()..
    – Sally CJ
    May 19, 2021 at 3:32

1 Answer 1

0

Thank you very much @Tom J Nowell and @Sally CJ .

As you pointed out, it worked with the below:

function remove_inline_style(){
   if ( is_page( 'live' ) ){
    

   remove_action( 'wp_enqueue_scripts', array( Design_Scheme::get_instance(), 'header_style_css' ), 11 );


   }
 }
 add_action( 'wp_enqueue_scripts', 'remove_inline_style');

thank you for your help.

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.