Resolving Issues With CDN and Aqua Resizer

WP Rocket v2.5.5

In v 2.5.5 of WP Rocket we have fixed the issue with images not being added to the CDN when your theme or a plugin uses the Aqua Resizer script. 

However, if you are using an older version of WP Rocket, please see below for how to resolve this issue. If you need help implementing the below, you may open a support ticket and we will help you.

Instructions for WP Rocket v2.3.8 up to and including v2.5.4

If your theme or a plugin is utilizing a resizing script called   Aqua Resizer the images on which it is applied will not be served from your CDN. You can check for the presence of the function in your theme code: 

aq_resize();

To fix this issue you can add the following code to your theme's functions.php file or place it in an MU plugin

add_action( 'init', '__rocket_cdn_on_aqua_resizer_238' );
function __rocket_cdn_on_aqua_resizer_238() {
	if( function_exists( 'aq_resize' ) ) {
		remove_filter( 'wp_get_attachment_url' , 'rocket_cdn_file', PHP_INT_MAX );
		add_filter( 'rocket_lazyload_html', '__rocket_cdn_on_data_lazy_src_attr_238' );
	}
}
function __rocket_cdn_on_data_lazy_src_attr_238( $html ) {
	if( preg_match( '/data-lazy-src=[\'"]?([^\'"\s>]+)[\'"]/i', $html, $matches ) ) {
		$html = str_replace( $matches[1], get_rocket_cdn_url( $matches[1], array( 'all', 'images' ) ), $html );
	}
	return $html;
}

Instructions for v 2.3.7 and older

You will have to edit the code of theme as described below in order to apply our filter.

The original code will look something like the following: 

<?php
$thumb 	 = get_post_thumbnail_id(); 
$img_url   = wp_get_attachment_url( $thumb,'full'); // Get img URL
$image 	 = aq_resize( $img_url, $w, $h, true );   // Resize & Crop img 
?>
<img src="<?php echo $image ?>" />

Replace that with the following in order to serve those images from your CDN:

<?php
$thumb = get_post_thumbnail_id(); 
// Remove WP Rocket CDN which cause conflict
remove_filter( 'wp_get_attachment_url' , 'rocket_cdn_file', PHP_INT_MAX );
$img_url = wp_get_attachment_url( $thumb,'full'); // Get img URL
$image 	 = aq_resize( $img_url, $w, $h, true );   // Resize & Crop img 
// Add WP Rocket CDN
add_filter( 'wp_get_attachment_url', 'rocket_cdn_file', PHP_INT_MAX );
$image = get_rocket_cdn_url( $image );
?>
<img src="<?php echo $image ?>" />