Change theme output path
-
Hi,
I am trying to put your plugin on my page which is running on bedrock, trellis and sage. I have my uploads folder link outside to shared folder currenct release. By few changes I was able to convers files in uploads but themes give me a struggle.This is code I am using now
add_filter('webpc_dir_path', function ($path, $directory) { $divided_path = explode('/', dirname(__FILE__)); $site_path= implode('/', array_slice($divided_path, 0, 7)); switch ($directory) { case 'uploads': return $site_path.'/uploads'; case 'webp': return $site_path.'/uploads/uploads-webpc'; case 'themes': return $site_path.'/themes'; case 'plugins': return $site_path.'/plugins'; } return ABSPATH; }, 10, 2); add_filter( 'webpc_uploads_prefix', function( $prefix ) { return '/'; } ); add_filter( 'webpc_site_root', function( $path ) { $divided_path = explode('/', dirname(__FILE__)); $site_path= implode('/', array_slice($divided_path, 0, 7)); return $site_path; // your valid path to root } ); add_filter('webpc_dir_name', function ($path, $type) { switch ($type) { case 'themes': return 'themes'; case 'plugins': return 'plugins'; } return ABSPATH; }, 10, 2);
WebP images are saved to
uploads/uploads-webpc
and then normal uploads structure. But theme files don’t follow this and are saved like thisuploads/uploads-webpc/srv/www/test.com/current/web/app/themes/test-theme/resources/assets/images/XYZ
.
I would like to save them to structureuploads/uploads-webpc/themes/test-theme/resources/assets/images/XYZ
.Is this somehou possible?
I did some investigation and what I need is to have option to change output of this piece of code
str_replace( realpath( $uploads_root ) ?: '', '', realpath( $path ) ?: '' );
.
It is in OuputPath::get_directory_path function. If you can add some filter there, it will be really helpfull.This is my config code
location ~ /app/(?<dir>uploads)/(?<path>.+)\.(?<ext>jpe?g|png|gif)$ { if ($http_accept !~* "image/webp") { break; } add_header Vary Accept; expires 365d; try_files /app/uploads/uploads-webpc/$path.$ext.webp $uri =404; } location ~ /app/(?<dir>plugins|themes)/(?<path>.+)\.(?<ext>jpe?g|png|gif)$ { if ($http_accept !~* "image/webp") { break; } add_header Vary Accept; expires 365d; try_files /app/uploads/uploads-webpc/$dir/$path.$ext.webp $uri =404; }
Thank you for answer,
Zbynek
- The topic ‘Change theme output path’ is closed to new replies.