- Section
- Troubleshooting – Icons missing from the blocks
- Spectra Patterns
- How to Set Multiple Column Fields in Contact Form 7 Styler of Spectra?
- Styling Checkbox / Radio / Acceptance control in Contact Form 7 Designer block of Spectra
- Unable to Style Checkbox / Radio Buttons / Acceptance Control using Contact Form 7 Styler of Spectra
- Tab Index – for multiple Gravity Forms
- Getting Started With Spectra
- How to Exclude A Heading from Table of Contents?
- Spectra – Display Conditions for Blocks
- Installing and Importing Starter Templates
- Getting Started With Spectra
- Manually Install Spectra via FTP
- Automatic Beta Updates for Spectra
- Rollback To Previous Versions
- How to Load Google Fonts Locally
- Activate the Spectra Pro License Key
- How to Install Spectra Pro Plugin
- Translate Spectra Strings using Loco Translate
- How to Process Refund Requests?
- How to add a Transparent / Sticky header?
- How to Change the Site Logo?
- How to Change Global Styles?
- How to Disable Title on Posts, Pages?
- How to add a transparent/ sticky header for a single page/post?
- Change Header and Footer Patterns in Spectra One Theme
- Add Custom/Google Fonts In Spectra One
- How To Reset Global Default Styling?
- Manually Install Spectra One via FTP?
- Disable or Enable Header/Footer for Specific Pages/Posts
How to Regenerate Spectra Assets Using Custom Code
The ‘Regenerate Assets’ button under Spectra > Settings > Asset Generation allows users to regenerate CSS and JS assets:
For example, if you update your site and visitors still see old styles, regenerating assets fixes this.
By doing it programmatically, you can trigger the refresh through your plugin or backend, saving time with every website update.
Regenerating Spectra Assets Automatically
Spectra regenerates its CSS and JS files by updating something called the asset version (__uagb_asset_version).
To trigger this, we can update that version number using a custom function in your functions.php file. This is how you can automate it:
Step 1: Update The Asset Version
You can update the asset version using the update_option() function in WordPress, like this:
update_option( '__uagb_asset_version', time() );
Note: The time() function ensures a unique timestamp is used, forcing Spectra to regenerate the assets.
Step 2: Hooking The Version Into Actions
You can set this process to run automatically when certain actions happen on your site, like saving a post.
To do that, you add this code to your functions.php file:
add_action( 'save_post', 'regenerate_page_assets', 10 );
function regenerate_page_assets() {
// Update the asset version to trigger regeneration
update_option( '__uagb_asset_version', time() );
}
This code hooks into the save_post action and tells WordPress to regenerate Spectra’s assets whenever a post or page is saved. That way, your site’s CSS and JS files stay updated automatically.
You can hook this into various WordPress actions (such as save_post and more).
That’s all! If you have any questions, feel free to contact our support team.
We don't respond to the article feedback, we use it to improve our support content.