get_rocket_cdn_url()
WP Rocket rewrites all the URLs of your images to the CDN URL. However, in rare cases image URLs may not be rewritten, because the theme, or a plugin does not use native WordPress functions to display images.
It is possible to use one of WP Rocket’s own functions to force the rewrite of the image URL in such cases.
For example, if your logo is displayed with a function call like this one:
<img src="<?php echo get_option( 'logo_url' ); ?>" />
…you can simply wrap get_rocket_cdn_url()
around that function call like this:
/* Check if WP Rocket’s function exist to avoid conflicts. */ <?php if ( function_exists( 'get_rocket_cdn_url' ) ) : ?> <img src="<?php echo get_rocket_cdn_url( get_option( 'logo_url' ) ); ?>" /> <?php else: /* Fallback in case WP Rocket is not active. */ ?> <img src="<?php echo get_option( 'logo_url' ); ?>" /> <?php endif; ?>
Heads up! This is a simplified code example. Always secure output like options with proper escaping!