WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm wondering--what is the best way to prevent a file (say, a custom CSS file associated with a plugin) from being overwritten during the update process?

Would setting the file's status as immutable do the trick, or would this just cause an error during update? What is the best way to go about doing this?

share|improve this question
Can you give an example to a situation where such thing is required? What is the difference if the file is overwritten with the same code during the upgrade or being excluded from the upgrade? – Mark Kaplun Dec 14 '12 at 5:15
My issue is that the plugin upgrade process overwrites my custom CSS. Say for example I have a slider plugin which overwrites a CSS file every time the upgrade runs. I would like to prevent ONLY that one file from being overwritten. – FurryWombat Dec 14 '12 at 8:20
up vote 0 down vote accepted

Basically you should not include the file in the plugin in the first place. If the reason you don't want it to be overwritten is because you modify it based on some local setting, then you should leave the immutable part of the file in it and create another file which will contain the mutable parts.

Then you can use your CSS like that (assuming you suplly constant.css with the plugin and generate costum.css locally.


function my_plugin_addcss() {

  // register and enqueue the immutable part
  wp_register_style('constantStyle', WP_PLUGIN_URL . '/my_plugin/constant.css');

  // register and enqueue the custom part
  wp_register_style('costumStyle', WP_PLUGIN_URL . '/my_plugin/costume.css');
share|improve this answer
I am not the author of the plugin. Are you saying I should force a deregistering of the plugin CSS file from outside the plugin files, then register my own elsewhere? What if the hook or name changes at some point in the future? – FurryWombat Dec 14 '12 at 10:06
I understand the problem and I don't know a good solution for your problem. Why don't you just include another CSS in your theme that overrides the rules of the plugin's CSS instead of changing the plugin itself? – Mark Kaplun Dec 14 '12 at 10:35
Well, that just feels like a hack. What if the plugin author decided that they wanted to add !important to all of their CSS? This would nullify my previous adjustments. – FurryWombat Dec 14 '12 at 15:35
And what if the plugin's PHP code will be changed in a way not compatible with the rest of your code? what if it will stop being updated and will not be fixed when it will become incompatible with future WP? Then the plugin do not meet your needs anymore and you look for a replacement. I know that the mantra is to always upgrade, but if the site is important then you have to test before you upgrade. – Mark Kaplun Dec 14 '12 at 16:18
Rarely would I ever change PHP of a plugin, but you do make a solid point. When the heck is WP going to make the move to MVC, so we can start using vQmod?? Argh! – FurryWombat Dec 14 '12 at 19:24

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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