Style.css file gets restored to default version

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.

deneme bonusudeneme bonusu veren sitelerpulibet girişOnwin Güncel Giriştürkçe altyazılı pornocanlı bahis casino