1

I am using wordpress and I am facing an issue.

Whenever I made any changes to the themes style.css file.

Everyday after certain hrs. The file gets restored to it's default version automatically.

All my changes gets undone.

i am not using git. I am using Go-Daddy as server provider.

i am using the "twenty-twenty" theme.

What can be the reason for that ?

4
  • 2
    You've tagged your question with wordpress.com-hosting - is this a self-hosted WordPress site, or are you using wordpress.com as your host? If the latter, you'll need to ask their support team about this.
    – Pat J
    Jan 31 at 15:37
  • does your host rely on git? Can you provide more information? Are you using wp.com as Pat suggested?
    – Tom J Nowell
    Jan 31 at 16:12
  • i am using godaddy for server. i am not using git. Jan 31 at 16:27
  • 1
    I ask because a lot of managed hosts use git to track files, and if you manually modified the files then security checks would undo that modification so it matched the git repo. How ar eyou modifying the file? Have you spoken with your host about it? Do you have security and backup software/plugins active? Likewise if you're modifying a theme directly and not using a child theme then your modifications get overwritten when updates are applied, and security software might flag those change as malicious
    – Tom J Nowell
    Jan 31 at 16:51

2 Answers 2

3

Below is a generic response to help you, but first I want to give you my personal opinions based on my experiences with issues regarding using stylesheets with WordPress.

  • I never use the themes generic style.css file due to issues like this and other common issues. Google no longer penalizes you for having extra .css files in your site. I could be wrong but I don't think so.
  • I always add a new stylesheet file and add cache busting code that keeps it updated to your latest version. Here is how I do that: First I make sure I have a child theme, if you don't have a child theme then that is your issue. You can also use a custom plugin but the gist is the same, add a new css file (google no longer penalizes you for having extra files in your site) Cache busting is the trick, using cache busting you will always see your new changes. Either create a custom plugin or a child theme and add this to your functions / plugin file:

This is for a custom plugin:

function wpb_custom_addons_scripts() {
    $ver = mt_rand(1000, 100000); // version which disables caching of scripts and styles
//    $ver = '1.9991'; // version which enables caching of scripts and styles

    wp_register_style( 'wpb_addons_style', plugins_url( 'includes/css/style.css', __FILE__ ), array(), $ver );
    wp_enqueue_style( 'wpb_addons_style' );

    wp_register_script( 'wpb_addons_script', plugins_url( 'includes/js/script.js', __FILE__ ), array('jquery'), $ver );
    wp_enqueue_script( 'wpb_addons_script' );
}

add_action( 'wp_enqueue_scripts', 'wpb_custom_addons_scripts' );

This is for a child theme:

function wpb_custom_addons_scripts() {
    $ver = mt_rand(1000, 100000); // version which disables caching of scripts and styles
    // $ver = '1.9991'; // version which enables caching of scripts and styles

    wp_register_style( 'wpb_addons_style', get_stylesheet_directory_uri() . '/includes/css/style.css', array(), $ver );
    wp_enqueue_style( 'wpb_addons_style' );

    wp_register_script( 'wpb_addons_script', get_stylesheet_directory_uri() . '/includes/js/script.js', array('jquery'), $ver );
    wp_enqueue_script( 'wpb_addons_script' );
}

add_action( 'wp_enqueue_scripts', 'wpb_custom_addons_scripts' );

Notice the $ver variable, while it is using mt_rand() your css file is loaded every page load. Great for development. Once you are done developing you can use this: $ver = '1.9991' Then every time you update your code increase your version number so the site uses your new code. That is cache busting.

  • If my changes are basic and very little I put my custom css in the custom css section like this:

Access the Customizer:

Log in to your WordPress dashboard. Navigate to "Appearance" on the left sidebar. Click on "Customize" to open the theme customizer.

Locate the Additional CSS Section:

In the theme customizer, scroll down until you find the "Additional CSS" section. Click on it to open the CSS editing area and put your code there.


The issue you're experiencing with your WordPress theme's style.css file reverting to its default version after certain hours could be caused by several factors:

Caching Plugins or Server Caching: If you're using caching plugins like WP Rocket or server-level caching, they might be restoring a cached version of the style.css file. Ensure that your caching settings are correctly configured and try clearing the cache after making changes to the style.css file.

Child Theme: If you're not using a child theme, any updates to the main theme (either automatic or manual) can overwrite your customizations. To avoid this, create and activate a child theme, and make your CSS changes in the child theme's style.css file.

Automatic Theme Updates: If your theme is set to update automatically, it might be replacing your customized style.css file with the default one from the update. You can disable automatic theme updates to prevent this.

Managed WordPress Hosting: Some managed WordPress hosting solutions have features that restore files to a known state for security reasons. Check with your hosting provider if such features are active.

Version Control Systems: If your site is under a version control system like Git, and the deployment process is automated, it might be reverting the style.css file to the version stored in the repository.

Security Plugins: Some security plugins might revert changes to core files (like those of themes) if they perceive them as unauthorized changes.

File Permissions: Incorrect file permissions can sometimes lead to issues where changes are not saved correctly. Ensure that your style.css file has the correct file permissions.

To troubleshoot, you can:

Check your site’s error logs and the server’s error logs for any relevant messages. Temporarily disable caching and security plugins to see if the issue persists. Ensure you're using a child theme for your customizations. Check with your hosting provider for any features or configurations that might cause this behavior. Remember to always back up your site before making changes, especially when troubleshooting issues like this.

2

Are you using a theme you purchased? If so, your changes will get overwritten anytime that theme is updated. Depending on how the theme was built, it could also be overwriting the CSS file via a .scss file or .js file.

You will need to install a child theme and edit the theme files within that new child theme. You shouldn't edit the parent theme or you will eventually run into the same issue. But you can copy theme files from the parent theme into the child theme and edit them there.

Another option would be to go to Appearance > Customize > Additional CSS to add new CSS.

Hope this helps!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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