CDN compatibility with WPLMS

For Sites using CDN.

WPLMS uses standard WordPress functions to display images. However, when images are loaded via an ajax call it is possible that the images load directly from the server rather than the CDN.


The example below assumes PHOTON CDN, you’ll need to contact your corresponding CDN’s for help on this.

function static_counter( $url ) {
        srand( crc32( basename( $url ) ) );
        $static_counter = rand( 0, 2 );
        return $static_counter;

add_filter ( 'post_thumbnail_html','wplms_cdn_ajax_image_handle',10,4);
function wplms_cdn_ajax_image_handle($html,$post_id,$post_thumbnail_id, $size){

	$url = wp_get_attachment_image_src($post_thumbnail_id,$size);
	if (strpos($url,'http://') !== false)

	return '<img src="http://i'.static_counter($url).''.$url.'">';


Was this article helpful?

Related Articles


  1. mesrick

    So this allows the image to be loaded from the CDN, preventing ajax from overriding it and causing it to be loaded by the server?

Leave A Comment?