• Resolved phuongdnx

    (@phuongdnx)


    The theme I’m using can display on homepage a grid of featured images of posts and automatically fit images in size and position.
    Basically, it’s use the srcset attribute of img tag, and I set Nelio Content auto detect first image in a post as featured image.
    To make the homepage display correctly, generated img tag of a post is like this:
    ———————————————–
    <img style="background:url(img_url) no-repeat center center;-webkit-background-size:cover;-moz-background-size:cover;-o-background-size:cover;background-size: cover;" src=”img_url” srcset=”img_url 1920w, img_url 300w, …” … />
    ———————————————–

    But with first external image as featured image, it becomes:
    ————————————————
    <img style="background:url(img_url) no-repeat center center;-webkit-background-size:cover;-moz-background-size:cover;-o-background-size:cover;background-size: cover;" src=”https://domain/nc-efi-placeholder.png&#8221; srcset=”https://domain/nc-efi-placeholder.png 1920w, https://domain/nc-efi-placeholder-300×169.png 300w, …” … />
    ————————————————
    Is there anyway that make all those placeholder image to be replaced by external image url?

    Thanks

    • This topic was modified 8 years, 4 months ago by phuongdnx.
    • This topic was modified 8 years, 4 months ago by phuongdnx.
    • This topic was modified 8 years, 4 months ago by phuongdnx.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author David Aguilera

    (@davilera)

    Hi!

    You can add the following snippet in your theme’s functions.php file (or in a custom plugin where you add your custom tweaks):

    
    add_filter( 'post_thumbnail_html', 'nelio_use_full_efi', 99, 2 );
    function nelio_use_full_efi( $html, $post_id ) {
    
    	if ( ! class_exists( 'Nelio_Content_External_Featured_Image_Helper' ) ) {
    		return $html;
    	}//end if
    
    	$aux = Nelio_Content_External_Featured_Image_Helper::instance();
    	$nelio_featured_image = $aux->get_nelio_featured_image( $post_id );
    	if ( ! is_string( $nelio_featured_image ) || ! strlen( $nelio_featured_image ) ) {
    		return $html;
    	}//end if
    
    	return sprintf( '<img src="%s" />', esc_url( $nelio_featured_image ) );
    
    }//end nelio_use_full_efi()
    

    The previous function checks if the current post $post_id has an external featured image using our helper class Nelio_Content_External_Featured_Image_Helper. If it does, it returns a new img tag that uses that URL directly (without wrappers).

    Please, let me know if this solved your problem!

    Best,
    David

    Thread Starter phuongdnx

    (@phuongdnx)

    Yeah, it works perfectly.
    Thanks a lot

    Plugin Author David Aguilera

    (@davilera)

    Cool! ??

    Oh and, please, don’t forget to rate and comment on our plugin ??

    Thread Starter phuongdnx

    (@phuongdnx)

    sure ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Auto external featured image in grid-home theme’ is closed to new replies.