0

I´m creating a plugin and I need, when the admin is logged in and a single-{post-type-slug}.php does not exist, the page https://my-site/post-type-slug/my-admin-page.php can be displayed without loading the theme css.

I tried :

wp_dequeue_style('screen');
wp_deregister_style('screen');

wp_dequeue_style('style');
wp_deregister_style('style');


wp_dequeue_style('style.css');
wp_deregister_style('style.css');

wp_dequeue_style( 'wpsl-styles' );

Inside my Object like this...

 add_action( 'wp_print_scripts', array( $this , "remove_style" ), 100000 );

 or

 add_action( 'wp_enqueue_scripts', array( $this , "remove_style" ), 100000 );


and

public function remove_style(){
    wp_dequeue_style( 'wpsl-styles' );
    //wp_dequeue_style("style");
    //wp_deregister_style("style");
    global $wp_styles;
    foreach( $wp_styles->queue as $style ) :
        echo $wp_styles->registered[$style]->src . "<br/>";
    endforeach;
}

Nothing works (Wordpress 5.x) and it´s a system to remove only style.css. I would like to find a way for my plugin to remove all styles except for the WordPress admin bar.

Anyone got an idea ?

0

I found a way to list all the handles and after that, I chose all css I wanted to keep to do this function :

//call in my object
add_action( 'wp_enqueue_scripts', array( $this , "clean_styles" ), 9999 );

public function clean_styles(){
    wp_debug_log();
    global $wp_styles;
    foreach( $wp_styles->queue as $style ) :
        //List the css src and handle
        //echo $wp_styles->registered[$style]->src . " - ";
        //echo $wp_styles->registered[$style]->handle . "<br/>";
        $handle = $wp_styles->registered[$style]->handle;
        //array of css I want to keep
        $css_exception = [ "wp-block-library", "wp-block-library-theme", "admin-bar" ]
        if( !in_array( $handle, $css_exception ) ){
            wp_dequeue_style( $handle );
            wp_deregister_style( $handle );
        }
    endforeach;
        //echo "<br/><br/>";
    //List the css list I kept
    /*foreach( $wp_styles->queue as $style ) :
        echo $wp_styles->registered[$style]->src . "<br/>";
    endforeach;*/
}

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.