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
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?header_style_css()
function is not a global function; it's a class method, so when using it withremove_action()
, you need to use the object method (more details here), e.g.array( $object, 'method' )
. And in your case, that object isDesign_Scheme::get_instance()
- see at the very bottom here. Also, note that we dequeue a CSS file usingwp_dequeue_style()
and notwp_dequeue_script()
..