I'm now writing a plugin that hook with a [TAG] on a page. From now every thing work well except for the custom css. I've writing my plugin on a developement station with basic theme (20-14 I think). When I've put my plugin in the real site, that was very ugly because site theme css where not handle. There is a way to reset or remove all css in a plugin. I ask this because if one day I want to change my theme, I will have to rewrite my plugin to handle more theme css. From now i've tries the hard way with wp_deregister_style('slug').

add_action( 'wp_enqueue_scripts', 'my_scripts_method');


 function my_scripts_method() {    
//    wp_deregister_style('open-sans-css');
//    wp_deregister_style('rs-settings-css');
//    wp_deregister_style('rs-captions-css');
//    wp_deregister_style('rs-plugin-static-css');
//    wp_deregister_style('wp125style-css');
//    wp_deregister_style('u-design-reset-css');
//    wp_deregister_style('u-design-text-css');
//    wp_deregister_style('u-design-grid-960-css');
//    wp_deregister_style('u-design-superfish_menu-css');
//    wp_deregister_style('u-design-pretty_photo-css');
//    wp_deregister_style('u-design-style-css');
//    wp_deregister_style('u-design-custom-style-css');
//    wp_deregister_style('u-design-responsive-css');
//    wp_deregister_style('u-design-style-orig-css');
//and continue....

But it's doesn't work. Even if this work, I will have to completly re-begin if I change my theme. There is a way to put a reset css like or put everything to 0?

Sorry for my bad english, i'm french.

Francois

  • I assume you are trying that code without the line comments? – s_ha_dum Mar 8 '14 at 19:52
  • yes, I use without the line comments – f.soucy Mar 9 '14 at 0:44
up vote 1 down vote accepted

You can try this function.

function remove_all_theme_styles() {
    global $wp_styles;
    $wp_styles->queue = array();
}
add_action('wp_print_styles', 'remove_all_theme_styles', 100);

This should work on any theme, but its not really a good approach to disable theme css just to make your plugin look good.

  • Thanks for your solution. What other solution the plugin writer use to make their plugin to look good? I've tried the css way, but I found this hard to think all options I should put just in case of... – f.soucy Mar 12 '14 at 19:59
  • If you are creating a public plugin that other users will use, consider these notes. 1) Try to use unique classes and IDs for the HTML output of your plugin on the frontend. 2) Add a plugin specific CSS & js files, that will take care of design of the plugin output. 3) Users would like to have a nice looking plugin, but not with a compromise to damage the whole theme output, so disabling the theme CSS is really a bad solution. – Domeniko Mar 13 '14 at 19:11
  • 4) "I've tried the css way, but I found this hard to think all options I should put just in case of... " - thats a typical problem for perfectionists usually, they want to make it perfect and include all possible features : )) Instead, create plugin with the features you think are vital, you will develop and improve it further, also you can listen to the feedback of the users, they will give you bunch of great (and a bunch of silly as well) ideas for plugin improvement. – Domeniko Mar 13 '14 at 19:15
  • Thank Archie. You make one point when you said that I'm perfectionists! In fact, my plugin is in version 2. The first one was to test user reaction. The reaction was they love it, but some feature was missing. For the design output I will remember what you said! Thank again :) – f.soucy Mar 13 '14 at 23:20

You should probaby use

wp_dequeue_style();
  • Please explain your answer in more detail. – s_ha_dum Mar 8 '14 at 20:21
  • Sormano, thank but even if this work, it will not work anymore if I change my theme. I search for something that's definitive, something that I will not need to check anymore in case of theme changing. – f.soucy Mar 9 '14 at 0:45
  • Best you can do is create a css file for your plugin and set your style in there. It's not recommended to unload someones style to make your plugin work/pretty. – Sormano Mar 9 '14 at 12:31
  • Sormano: I've done this so far... But it's not the best thing. If I change my theme, I will need to redo this.. :/ – f.soucy Mar 11 '14 at 4:50

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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