Hi all,
I would like to use a CDN with Lay Theme. As some research has shown in the forum there does not seem to be an official way to integrate a CDN fully. Investigating the website after CDN activation shows me all JS, stylesheets and fonts load from the CDN, but the images do not load from there, but locally.
I have identified two two sources for image urls, that would require to adopt the cdn path. Both are part of the wordpres REST API.
This will rewrite the local domain path (mydomain.com') to the cdn domain (abcdef.stackpathcdn.com) for all calls of get_attachment_image_src. This will only be active after re saving the corresponding pages. Its added in the functions.php of my child theme:
function filter_wp_get_attachment_image_src( $image, $attachment_id, $size, $icon ) {
if(isset($image[0]))
{
$image[0] = str_replace(
'mydomain.com',
'abcdef.stackpathcdn.com',
$image[0]);
}
return $image;
};
add_filter( 'wp_get_attachment_image_src', 'filter_wp_get_attachment_image_src', 99, 4 );
Similarly Lay Theme seems to store a bunch of prepared JSON for Gridder in options fields. This JSON seems to deliver the image URLs relative (without protocol or domain). I was looking for a Wordpress filter to filter for any call to get_option for any option containing "_gridder_json" in their name, yet could not find a catch all filter for this. Does anyone have a tip on how to achieve this? WOuld be nice if I could also load the images from the CDN, which will improve page speed dramatically.
Best, MM