Estimated reading time: 2 min
📌 Configure a Cron Job to Regenerate the CSS File in WordPress. CSS files play a crucial role in the appearance and performance of a WordPress site. However, caching can sometimes prevent recent style changes from displaying correctly. A practical solution is to set up a Cron Job to periodically regenerate the CSS file, ensuring users always see the latest version.
🔧 Why Use a WordPress Cron Job?
- Prevents issues caused by caching.
- Automates CSS regeneration without manual intervention.
- Improves performance and ensures quick style updates.
Step 1: Locate Your CSS File
In most WordPress themes, the primary CSS file is located at:
/wp-content/themes/your-theme/style.css
If you’re using a caching plugin or a page builder, check the correct location of the minified CSS file.
Step 2: Create a PHP Script to Refresh the CSS
Create a new file, e.g., refresh-css.php
, and add the following code:
<?php
$file = __DIR__ . "/wp-content/themes/your-theme/style.css";
if (file_exists($file)) {
touch($file);
echo "CSS file has been successfully regenerated!";
} else {
echo "Error: CSS file not found!";
}
?>
This script updates the CSS file’s timestamp, forcing browsers to load the latest version.
Step 3: Set Up a Cron Job in cPanel
- Log in to cPanel and go to the Cron Jobs section.
- Add a new Cron Job and set the execution frequency (e.g., every hour):
0 * * * * /usr/bin/php /home/user/public_html/refresh-css.php
(Make sure the file path is correct!)
3. Save the settings and check if the script runs correctly.
Step 4: Test the Cron Job Execution
To verify if the script is working:
- Run the command manually in the terminal:
php /home/user/public_html/refresh-css.php
- Check if the CSS has an updated timestamp.

🔍 Conclusion
Setting up a Cron Job for CSS file regeneration in WordPress is a simple yet effective way to bypass cache issues and ensure users always see the latest design updates.
📩 Have questions or suggestions? Leave a comment or contact us!
Tags: WordPress, CSS Regeneration, CSS Cron Job, Website Optimization, cPanel, WordPress Performance, Web Development, PHP Script, WordPress Theme, CSS Update WordPress
Discover more from HelpZone
Subscribe to get the latest posts sent to your email.