How to Use Autoptimize with WP Ghost for Speed and Security

Moved

This tutorial has moved to the new WP Ghost Knowledge Base where each feature is presented in detail.

View on new site

WP Ghost and Autoptimize are fully compatible. Use Autoptimize to combine and minify CSS/JS for performance, and WP Ghost to secure paths and change cache file references so the optimized files do not reveal your WordPress setup.

Why Use Both Plugins Together

Autoptimize and WP Ghost solve two different problems that work together to make your site faster and more secure at the same time.

Autoptimize is a performance optimization plugin. It combines your CSS and JavaScript files into fewer requests, minifies the code to reduce file sizes, and optimizes HTML output. This directly improves page load times and Core Web Vitals scores.

WP Ghost is a hack prevention plugin. It changes all default WordPress paths, blocks hacker bots with the 8G Firewall, and adds brute force protection and 2FA. But Autoptimize does not include any security features, and WP Ghost does not minify or combine files. They each handle what the other does not, which is why they complement each other so well.

The one area where they overlap is cached file paths. Autoptimize generates cached CSS and JS files in a default directory that can reveal you are using the plugin. WP Ghost can change the paths inside those cached files so they match your secured paths. Here is how to configure both plugins for the best results.

Step 1 – Configure Autoptimize for Performance

Start by setting up Autoptimize for optimal CSS and JavaScript handling.

1. Go to Settings > Autoptimize in your WordPress dashboard.

2. Under the JS, CSS & HTML tab, check Optimize JavaScript Code and Optimize CSS Code.

3. Optionally enable Aggregate JS-files and Aggregate CSS-files to combine multiple files into single requests. This reduces the number of HTTP requests your site makes, which improves load times.

4. Click Save Changes and Empty Cache.

Autoptimize JavaScript optimization settings with Aggregate JS option
Autoptimize CSS optimization settings with Aggregate CSS option

Test your site after enabling these options. Aggregating and inlining scripts can occasionally cause conflicts with page builders or interactive plugins. If something breaks, disable aggregation and keep only the minification enabled.

Step 2 – Configure WP Ghost Path Security

If you have not already configured WP Ghost, set it up now.

1. Go to WP Ghost > Change Paths.

2. Select Safe Mode or Ghost Mode (Premium).

Select Safe Mode

3. Customize your paths as needed and click Save.

For the complete setup, follow the Safe Mode setup guide or the WP Ghost Settings Best Practice guide.

Step 3 – Change Paths in Cached Files

This is the key step that makes both plugins work together seamlessly. When Autoptimize generates cached CSS and JS files, those files may still contain references to original WordPress paths like /wp-content/plugins/ or /wp-content/themes/. WP Ghost can automatically rewrite these references inside cached files.

1. Go to WP Ghost > Change Paths.

2. Scroll to the Change Paths in Cache Files option and switch it on.

3. Click Save.

WP Ghost automatically detects Autoptimize’s cache directory and rewrites the WordPress paths inside the cached files. This means even the optimized, combined CSS and JS files will use your custom paths instead of the default WordPress paths.

Step 4 – Map the Autoptimize Cache Directory (Optional)

By default, Autoptimize stores its cached files in a directory path that includes /wp-content/cache/autoptimize/. Even though WP Ghost changes /wp-content/ to a custom path, the word “autoptimize” in the URL still reveals which optimization plugin you are using.

You can use WP Ghost’s URL Mapping feature to change this path to something generic.

WP Ghost URL Mapping settings to change the Autoptimize cache directory path

1. Go to WP Ghost > Mapping > URL Mapping.

2. Add a mapping rule that changes the Autoptimize cache path to a custom name. For example, map /wp-content/cache/autoptimize/ to /custom-assets/static/.

3. Click Save.

This step is optional but recommended if you want full path security. It ensures that no part of your URL structure reveals which plugins you are using.

After Configuration – Clear All Caches

After configuring both plugins, clear all caches to make sure the new paths take effect:

1. In Autoptimize, go to Settings > Autoptimize and click Save Changes and Empty Cache.

2. If you have any other cache plugins (WP Rocket, LiteSpeed Cache, W3 Total Cache, etc.), clear those caches too.

3. If your hosting provider has a server-level cache (WP Engine, Kinsta, SiteGround, Cloudways, etc.), clear that as well.

4. Open your site in an incognito browser and view the page source. Search for “autoptimize” and “wp-content”. If neither appears, your configuration is working correctly.

Note: If WordPress cron is deactivated on your website, the paths in cached files may not update automatically. In that case, manually clear the Autoptimize cache and save the WP Ghost settings again to trigger the path replacement.

Frequently Asked Questions

Will WP Ghost slow down my site if I use it with Autoptimize?

No. WP Ghost and Autoptimize work at different levels and do not conflict with each other’s performance. Autoptimize optimizes file delivery. WP Ghost rewrites paths using lightweight server rules. Together they improve both speed and security without adding overhead.

Do I need to change paths in cache files if I use Autoptimize?

Yes, if you want complete path security. Without this option enabled, the cached CSS and JS files generated by Autoptimize will still contain references to original WordPress paths like /wp-content/plugins/. Enabling “Change Paths in Cache Files” in WP Ghost ensures those references are rewritten too.

Can I use other cache plugins instead of Autoptimize?

Yes. WP Ghost is compatible with over 15 cache plugins including WP Rocket, LiteSpeed Cache, W3 Total Cache, WP Super Cache, Breeze, Hummingbird, and more. The “Change Paths in Cache Files” feature works with all of them. See the full Plugin Compatibility List.

Autoptimize is showing errors after enabling WP Ghost. What do I do?

Clear the Autoptimize cache completely, then save WP Ghost settings again. If the issue persists, try disabling the “Aggregate” options in Autoptimize and keep only minification enabled. Some aggressive aggregation settings can conflict with path rewrites. For more troubleshooting, see the emergency disable guide.

Does WP Ghost modify WordPress core files?

No. WP Ghost uses server rewrite rules and WordPress hooks. No core files are moved, renamed, or modified. Deactivating the plugin restores all default paths instantly.