An “Autoptimize Critical CSS“-user saw some weirdness in how the site looked when optimized. The reason for this turned out to be not the critical CSS, but the fact that he used “Hide My WordPress Pro”, a plugin that changes well-known paths in WordPress URL’s to other paths (e.g. /wp-content/plugins -> /modules/ and /wp-content/themes -> /templates) and uses rewrite rules .htaccess to map requests to the filesystem. This resulted in Autoptimize not finding the files on the filesystem (as AO does not “see” the mapping in .htaccess), leaving them un-aggregated.
To fix something like that, a small code snippet that hooks into Autoptimize’s API can do the trick;
add_filter('autoptimize_filter_cssjs_alter_url', 'rewrite_hidemywp'); function rewrite_hidemywp($url) { if ( strpos( $url, 'modules/' ) !== false && strpos( $url, 'wp-content' ) === false ) { $url = str_replace('modules/','wp-content/plugins/', $url); } elseif ( strpos( $url, 'templates/' ) !== false && strpos( $url, 'wp-content' ) === false ) { $url = str_replace('templates/','wp-content/themes/', $url); } return $url; }
The above is just an example (as in the Pro version of hide-my-wp you can set paths of your own liking and you can even replace theme names by random-ish strings), but with a small amount of PHP-skills you should be able to work out the solution for your own site. Happy optimized hiding!
Beautiful ChillianGonzales just heard, on piano
Gr
Dees
Dag Dees ๐
Sooo… Where do we put that snippet of code?
The easiest and safest way would be using the code snippet plugin John.
hi Frank, Thank you for your excellent work. Can I customize the cache storage path? I don’t want it to be placed in the wp-content/cache. I want it to be placed in the root directory of the website
yes you can change the storage path, see the FAQ for info on how to do that Lee ๐
yes๏ผi find it yesterday.
define(‘AUTOPTIMIZE_CACHE_CHILD_DIR’,’/resources/’);
but, Can I change the directory & filename in website root?
e.g. /cache/autoptimize/js/
not /wp-content/cache/autoptimize/js/
I haven’t tried
thank you