WordPress.org

Ready to get started?Download WordPress

Forums

Jetpack by WordPress.com
[resolved] Featured Image is not served by WordPress CDN (5 posts)

  1. white04004
    Member
    Posted 1 year ago #

    Hi,

    I have just published a post with a featured image and some images in it.

    The images in the post are served by WordPress CDN but featured image is not. Is this a bug?

    http://wordpress.org/extend/plugins/jetpack/

  2. macgamer
    Member
    Posted 1 year ago #

    Check how your theme displays the featured image. Mine was using the get_the_image() function which doesn't support photon. wp_get_attachment_image_src() also appears not to work. Either use a different one, or do what I did and pass the URL through a custom function:

    // return photon server to use based on url 
    
    function static_counter( $url ) {
            srand( crc32( basename( $url ) ) );
            $static_counter = rand( 0, 2 );
            srand(); // this resets everything that relies on this, like array_rand() and shuffle()
    
            return $static_counter;
    }
    
    // fetch photon equivalent url
    
    function photon_url($url) {
    
    	if (strpos($url,'http://') !== false)
    	{
    	   $url=str_replace('http://','',$url);
    	}
    
    	return "http://i".static_counter($url).".wp.com/".$url;
    }
  3. white04004
    Member
    Posted 1 year ago #

    Thanks

  4. Michael Van Den Berg
    Member
    Posted 1 year ago #

    My theme is using the_post_thumbnail to fetch the featured image.

    Any suggestions how I could solve this?

  5. white04004
    Member
    Posted 1 year ago #

    I used the code by macgamer

    // return photon server to use based on url 
    
    function static_counter( $url ) {
            srand( crc32( basename( $url ) ) );
            $static_counter = rand( 0, 2 );
            srand(); // this resets everything that relies on this, like array_rand() and shuffle()
    
            return $static_counter;
    }
    
    // fetch photon equivalent url
    
    function photon_url($url) {
    
    	if (strpos($url,'http://') !== false)
    	{
    	   $url=str_replace('http://','',$url);
    	}
    
    	return "http://i".static_counter($url).".wp.com/".$url;
    }

    and I replaced the_post_thumbnail(); with

    $featured_image = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID)); // get thumbnail image url
    
    $photon_featured_image = photon_url($featured_image[0]);
    
    echo "<img src='".$photon_featured_image."' class='wp-post-image'> ";

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic