Recent posts thumbnail sizes

Hi

I’m trying to improve the loading times of my website. At the moment I have a few recent posts on the homepage, but they all load in full-size images. Is there any way to get the recent posts module to use thumbnail-sized images instead in order to improve load times?

Thanks.

Hi there,

To do that, please add this code in the functions.php file of your child theme:

// Add Excerpts to the recent post element
// =============================================================================
function x_shortcode_recent_posts_v2code( $atts ) {
  extract( shortcode_atts( array(
    'id'           => '',
    'class'        => '',
    'style'        => '',
    'type'         => 'post',
    'count'        => '',
    'category'     => '',
    'offset'       => '',
    'orientation'  => '',
    'no_sticky'    => '',
    'no_image'     => '',
    'fade'         => ''
  ), $atts, 'x_recent_posts' ) );

  $allowed_post_types = apply_filters( 'cs_recent_posts_post_types', array( 'post' => 'post' ) );
  $type = ( isset( $allowed_post_types[$type] ) ) ? $allowed_post_types[$type] : 'post';

  $id            = ( $id           != ''     ) ? 'id="' . esc_attr( $id ) . '"' : '';
  $class         = ( $class        != ''     ) ? 'x-recent-posts cf ' . esc_attr( $class ) : 'x-recent-posts cf';
  $style         = ( $style        != ''     ) ? 'style="' . $style . '"' : '';
  $count         = ( $count        != ''     ) ? $count : 3;
  $category      = ( $category     != ''     ) ? $category : '';
  $category_type = ( $type         == 'post' ) ? 'category_name' : 'portfolio-category';
  $offset        = ( $offset       != ''     ) ? $offset : 0;
  $orientation   = ( $orientation  != ''     ) ? ' ' . $orientation : ' horizontal';
  $no_sticky     = ( $no_sticky    == 'true' );
  $no_image      = ( $no_image     == 'true' ) ? $no_image : '';
  $fade          = ( $fade         == 'true' ) ? $fade : 'false';

  $js_params = array(
    'fade' => ( $fade == 'true' )
  );

  $data = cs_generate_data_attributes( 'recent_posts', $js_params );

  $output = "<div {$id} class=\"{$class}{$orientation}\" {$style} {$data} data-fade=\"{$fade}\" >";

    $q = new WP_Query( array(
      'orderby'             => 'date',
      'post_type'           => "{$type}",
      'posts_per_page'      => "{$count}",
      'offset'              => "{$offset}",
      "{$category_type}"    => "{$category}",
      'ignore_sticky_posts' => $no_sticky
    ) );

    if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();

      if ( $no_image == 'true' ) {
        $image_output       = '';
        $image_output_class = 'no-image';
      } else {
        $image              = wp_get_attachment_image_src( get_post_thumbnail_id(), 'thumbnail' );
        $bg_image           = ( $image[0] != '' ) ? ' style="background-image: url(' . $image[0] . ');"' : '';
        $image_output       = '<div class="x-recent-posts-img"' . $bg_image . '></div>';
        $image_output_class = 'with-image';
      }

      $output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . '" href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( sprintf( csi18n('shortcodes.recent-posts-permalink'), the_title_attribute( 'echo=0' ) ) ) . '">'
                 . '<article id="post-' . get_the_ID() . '" class="' . implode( ' ', get_post_class() ) . '">'
                   . '<div class="entry-wrap">'
                     . $image_output
                     . '<div class="x-recent-posts-content">'
                       . '<h3 class="h-recent-posts">' . get_the_title() . '</h3>'
                       . '<span class="x-recent-posts-date">' . get_the_date() . '</span>'
                     . '</div>'
                   . '</div>'
                 . '</article>'
               . '</a>';

    endwhile; endif; wp_reset_postdata();

  $output .= '</div>';

  return $output;
}

// =============================================================================

add_action('wp_head', 'change_recent_posts_to_v2');
function change_recent_posts_to_v2() {
  remove_shortcode( 'x_recent_posts' );
  add_shortcode( 'x_recent_posts', 'x_shortcode_recent_posts_v2code' );
}
// =============================================================================

The that controls the size of the recent post image in the code is:

$image  = wp_get_attachment_image_src( get_post_thumbnail_id(), 'thumbnail' );

https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/
https://codex.wordpress.org/Post_Thumbnails

Hope this helps.

Thank you for your help. I tried implementing that and got an error:

Your PHP code changes were rolled back due to an error on line 87 of file wp-content/plugins/cornerstone/includes/shortcodes/recent-posts.php. Please fix and try saving again.

Cannot redeclare x_shortcode_recent_posts() (previously declared in wp-content/themes/x-child/functions.php:27)

How do I fix that? Sorry for being a bit unsure!

Alex

Hi Alex,

My apologies for that. please update the previously suggested codes to:

function x_shortcode_recent_posts_v2( $atts ) {
  extract( shortcode_atts( array(
    'id'           => '',
    'class'        => '',
    'style'        => '',
    'type'         => 'post',
    'count'        => '',
    'category'     => '',
    'offset'       => '',
    'orientation'  => '',
    'show_excerpt' => 'true',
    'no_sticky'    => '',
    'no_image'     => '',
    'fade'         => ''
  ), $atts, 'x_recent_posts' ) );

  $allowed_post_types = apply_filters( 'cs_recent_posts_post_types', array( 'post' => 'post' ) );
  $type = ( isset( $allowed_post_types[$type] ) ) ? $allowed_post_types[$type] : 'post';

  $id            = ( $id           != ''     ) ? 'id="' . esc_attr( $id ) . '"' : '';
  $class         = ( $class        != ''     ) ? 'x-recent-posts cf ' . esc_attr( $class ) : 'x-recent-posts cf';
  $style         = ( $style        != ''     ) ? 'style="' . $style . '"' : '';
  $count         = ( $count        != ''     ) ? $count : 3;
  $category      = ( $category     != ''     ) ? $category : '';
  $category_type = ( $type         == 'post' ) ? 'category_name' : 'portfolio-category';
  $offset        = ( $offset       != ''     ) ? $offset : 0;
  $orientation   = ( $orientation  != ''     ) ? ' ' . $orientation : ' horizontal';
  $show_excerpt  = ( $show_excerpt == 'true' );
  $no_sticky     = ( $no_sticky    == 'true' );
  $no_image      = ( $no_image     == 'true' ) ? $no_image : '';
  $fade          = ( $fade         == 'true' ) ? $fade : 'false';

  $js_params = array(
    'fade' => ( $fade == 'true' )
  );

  $data = cs_generate_data_attributes( 'recent_posts', $js_params );

  $output = "<div {$id} class=\"{$class}{$orientation}\" {$style} {$data} data-fade=\"{$fade}\" >";

    $q = new WP_Query( array(
      'orderby'             => 'date',
      'post_type'           => "{$type}",
      'posts_per_page'      => "{$count}",
      'offset'              => "{$offset}",
      "{$category_type}"    => "{$category}",
      'ignore_sticky_posts' => $no_sticky
    ) );

    if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();

      if ( $no_image == 'true' ) {
        $image_output       = '';
        $image_output_class = 'no-image';
      } else {
        $image              = wp_get_attachment_image_src( get_post_thumbnail_id(), 'thumbnail' );
        $bg_image           = ( $image[0] != '' ) ? ' style="background-image: url(' . $image[0] . ');"' : '';
        $image_output       = '<div class="x-recent-posts-img"' . $bg_image . '></div>';
        $image_output_class = 'with-image';
      }

      $excerpt = ( $show_excerpt ) ? '<div class="x-recent-posts-excerpt"><p>' . preg_replace('/<a.*?more-link.*?<\/a>/', '', cs_get_raw_excerpt() ) . '</p></div>' : '';

      $output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . '" href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( sprintf( csi18n('shortcodes.recent-posts-permalink'), the_title_attribute( 'echo=0' ) ) ) . '">'
                 . '<article id="post-' . get_the_ID() . '" class="' . implode( ' ', get_post_class() ) . '">'
                   . '<div class="entry-wrap">'
                     . $image_output
                     . '<div class="x-recent-posts-content">'
                       . '<h3 class="h-recent-posts">' . get_the_title() . '</h3>'
		               . '<span class="recent-posts-author">' .the_author() . '</span>'
                       . '<span class="x-recent-posts-date">' . get_the_date() . '</span>'
                        . $excerpt
                     . '</div>'
                   . '</div>'
                 . '</article>'
               . '</a>';

    endwhile; endif; wp_reset_postdata();

  $output .= '</div>';

  return $output;

}

add_filter('wp_head', 'custom_recent_posts');

function custom_recent_posts() {
  remove_shortcode( 'x_recent_posts' );
  remove_shortcode( 'recent_posts' );
  add_shortcode( 'x_recent_posts', 'x_shortcode_recent_posts_v2' );
  add_shortcode( 'recent_posts', 'x_shortcode_recent_posts_v2' );
}

In case you are still having any issues with the code, please provide us with the FTP access to your site.

Hope this helps.

Thanks. No error this time, but instead the thumbnails are really zoomed in. It’s like a small section at the centre of the original thumbnail has been enlarged and made the entire thumbnail, if that makes sense.

Hi Alex,

Did you remove the code? Your recent posts looks fine on my end. Please clarify.

Thanks,

Yep I removed the code so it’s back in the original state. So the thumbnails are still the original images condensed down.

Is there a way to do it that uses smaller image files without distorting the thumbnails?

Hi There,

Please try with this code instead:

function x_shortcode_recent_posts_v3( $atts ) {
	extract( shortcode_atts( array(
		'id'           => '',
		'class'        => '',
		'style'        => '',
		'type'         => 'post',
		'count'        => '',
		'category'     => '',
		'offset'       => '',
		'orientation'  => '',
		// 'show_excerpt' => 'true',
		'no_sticky'    => '',
		'no_image'     => '',
		'fade'         => ''
	), $atts, 'x_recent_posts' ) );

	$allowed_post_types = apply_filters( 'cs_recent_posts_post_types', array( 'post' => 'post', 'mec-events' => 'mec-events' ) );
	$type = ( isset( $allowed_post_types[$type] ) ) ? $allowed_post_types[$type] : 'post';

	$id            = ( $id           != ''     ) ? 'id="' . esc_attr( $id ) . '"' : '';
	$class         = ( $class        != ''     ) ? 'x-recent-posts cf ' . esc_attr( $class ) : 'x-recent-posts cf';
	$style         = ( $style        != ''     ) ? 'style="' . $style . '"' : '';
	$count         = ( $count        != ''     ) ? $count : 3;
	$category      = ( $category     != ''     ) ? $category : '';
	//$category_type = ( $type         == 'post' ) ? 'category_name' : 'portfolio-category';

	if($type == 'post'){
		$category_type = 'category_name';
	} else if($type == 'mec-events'){
		$category_type = 'mec_category';
	} else {
		$category_type = 'portfolio-category';
	}

	$offset        = ( $offset       != ''     ) ? $offset : 0;
	$orientation   = ( $orientation  != ''     ) ? ' ' . $orientation : ' horizontal';
	// $show_excerpt  = ( $show_excerpt == 'true' );
	$no_sticky     = ( $no_sticky    == 'true' );
	$no_image      = ( $no_image     == 'true' ) ? $no_image : '';
	$fade          = ( $fade         == 'true' ) ? $fade : 'false';

	$js_params = array(
		'fade' => ( $fade == 'true' )
	);

	$data = cs_generate_data_attributes( 'recent_posts', $js_params );

	global $post;

	$output = "<div {$id} class=\"{$class}{$orientation}\" {$style} {$data} data-fade=\"{$fade}\" >";

		$q = new WP_Query( array(
		'orderby'             => 'date',
		'post_type'           => "{$type}",
		'posts_per_page'      => "{$count}",
		'offset'              => "{$offset}",
		"{$category_type}"    => "{$category}",
		'ignore_sticky_posts' => $no_sticky,
		'post__not_in'        => array($post->ID)
		) );

		if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();

			if ( $no_image == 'true' ) {
				$image_output       = '';
				$image_output_class = 'no-image';
			} else {
				$image              = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
				$bg_image           = ( $image[0] != '' ) ? ' style="background-image: url(' . $image[0] . ');"' : '';
				$image_output       = '<div class="x-recent-posts-img"' . $bg_image . '></div>';
				$image_output_class = 'with-image';
			}

			// $excerpt = ( $show_excerpt ) ? '<div class="x-recent-posts-excerpt"><p>' . preg_replace('/<a.*?more-link.*?<\/a>/', '', cs_get_raw_excerpt() ) . '</p></div>' : '';

			$output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . '" href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( sprintf( csi18n('shortcodes.recent-posts-permalink'), the_title_attribute( 'echo=0' ) ) ) . '">'
								 . '<article id="post-' . get_the_ID() . '" class="' . implode( ' ', get_post_class() ) . '">'
									 . '<div class="entry-wrap">'
										 . $image_output
										 . '<div class="x-recent-posts-content">'
											 . '<h3 class="h-recent-posts">' . get_the_title() . '</h3>'
											 . '<span class="x-recent-posts-date">' . get_the_date() . '</span>'
											 // . $excerpt
										 . '</div>'
									 . '</div>'
								 . '</article>'
							 . '</a>';

		endwhile; endif; wp_reset_postdata();

	$output .= '</div>';

	return $output;
}

add_action('wp_head', 'change_recent_posts_to_v3');
function change_recent_posts_to_v3() {
	remove_shortcode( 'x_recent_posts' );
	add_shortcode( 'x_recent_posts', 'x_shortcode_recent_posts_v3' );
}

Aftet that add this custom CSS under X > Theme Options > CSS:

.x-recent-posts .x-recent-posts-img {
    background-size: contain;
}

Let us know how it goes!

Thanks, that seems to have worked. The images aren’t all horribly zoomed/cropped any more.

There’s just one thing though - when I go to the homepage (after these changes have been implemented) and right-click one of the recent posts images > Inspect Element, it shows that the image used is still the full-size image, just very slightly downsized.

Is that right? I’m not savvy enough with code to work out exactly what’s happening in the code you’ve posted above, but surely the image used in recent posts should now be a smaller version of the post’s featured image, rather than the same larger file downsized?

Just a bit concerned it’ll still have an impact on load times.

Hello @AlexFST,

Thanks for updating the thread. :slight_smile:

Please update previously given code with following in child theme function.php file:

function x_shortcode_recent_posts_v3( $atts ) {
	extract( shortcode_atts( array(
		'id'           => '',
		'class'        => '',
		'style'        => '',
		'type'         => 'post',
		'count'        => '',
		'category'     => '',
		'offset'       => '',
		'orientation'  => '',
		// 'show_excerpt' => 'true',
		'no_sticky'    => '',
		'no_image'     => '',
		'fade'         => ''
	), $atts, 'x_recent_posts' ) );

	$allowed_post_types = apply_filters( 'cs_recent_posts_post_types', array( 'post' => 'post', 'mec-events' => 'mec-events' ) );
	$type = ( isset( $allowed_post_types[$type] ) ) ? $allowed_post_types[$type] : 'post';

	$id            = ( $id           != ''     ) ? 'id="' . esc_attr( $id ) . '"' : '';
	$class         = ( $class        != ''     ) ? 'x-recent-posts cf ' . esc_attr( $class ) : 'x-recent-posts cf';
	$style         = ( $style        != ''     ) ? 'style="' . $style . '"' : '';
	$count         = ( $count        != ''     ) ? $count : 3;
	$category      = ( $category     != ''     ) ? $category : '';
	//$category_type = ( $type         == 'post' ) ? 'category_name' : 'portfolio-category';

	if($type == 'post'){
		$category_type = 'category_name';
	} else if($type == 'mec-events'){
		$category_type = 'mec_category';
	} else {
		$category_type = 'portfolio-category';
	}

	$offset        = ( $offset       != ''     ) ? $offset : 0;
	$orientation   = ( $orientation  != ''     ) ? ' ' . $orientation : ' horizontal';
	// $show_excerpt  = ( $show_excerpt == 'true' );
	$no_sticky     = ( $no_sticky    == 'true' );
	$no_image      = ( $no_image     == 'true' ) ? $no_image : '';
	$fade          = ( $fade         == 'true' ) ? $fade : 'false';

	$js_params = array(
		'fade' => ( $fade == 'true' )
	);

	$data = cs_generate_data_attributes( 'recent_posts', $js_params );

	global $post;

	$output = "<div {$id} class=\"{$class}{$orientation}\" {$style} {$data} data-fade=\"{$fade}\" >";

		$q = new WP_Query( array(
		'orderby'             => 'date',
		'post_type'           => "{$type}",
		'posts_per_page'      => "{$count}",
		'offset'              => "{$offset}",
		"{$category_type}"    => "{$category}",
		'ignore_sticky_posts' => $no_sticky,
		'post__not_in'        => array($post->ID)
		) );

		if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();

			if ( $no_image == 'true' ) {
				$image_output       = '';
				$image_output_class = 'no-image';
			} else {
				$image              = wp_get_attachment_image_src( get_post_thumbnail_id(), 'medium' );
				$bg_image           = ( $image[0] != '' ) ? ' style="background-image: url(' . $image[0] . ');"' : '';
				$image_output       = '<div class="x-recent-posts-img"' . $bg_image . '></div>';
				$image_output_class = 'with-image';
			}

			// $excerpt = ( $show_excerpt ) ? '<div class="x-recent-posts-excerpt"><p>' . preg_replace('/<a.*?more-link.*?<\/a>/', '', cs_get_raw_excerpt() ) . '</p></div>' : '';

			$output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . '" href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( sprintf( csi18n('shortcodes.recent-posts-permalink'), the_title_attribute( 'echo=0' ) ) ) . '">'
								 . '<article id="post-' . get_the_ID() . '" class="' . implode( ' ', get_post_class() ) . '">'
									 . '<div class="entry-wrap">'
										 . $image_output
										 . '<div class="x-recent-posts-content">'
											 . '<h3 class="h-recent-posts">' . get_the_title() . '</h3>'
											 . '<span class="x-recent-posts-date">' . get_the_date() . '</span>'
											 // . $excerpt
										 . '</div>'
									 . '</div>'
								 . '</article>'
							 . '</a>';

		endwhile; endif; wp_reset_postdata();

	$output .= '</div>';

	return $output;
}

add_action('wp_head', 'change_recent_posts_to_v3');
function change_recent_posts_to_v3() {
	remove_shortcode( 'x_recent_posts' );
	add_shortcode( 'x_recent_posts', 'x_shortcode_recent_posts_v3' );
}

After that from Settings > Media > Medium size let’s have width and height as 300px. https://cloudup.com/cwQFxLpUqIe

I also suggest you to install Regenerate Thumbnails plugin to regenerate images. https://wordpress.org/plugins/regenerate-thumbnails/

Please note that the plugin I have shared is not a official Themeco advice. It’s just a personal input that I have shared with you to help you get started. 3rd party plugins may cause some issues and we won’t be able to provide support in that scenario.

Thanks.

Thanks for your help on this. My media settings already had medium images set to 300px, so that wasn’t the issue. I tried the code you gave and then regenerated all featured images, but the recent posts images remain the same as before.

I don’t really know what’s going wrong and why it’s still using full-size images :frowning:

Hello @AlexFST,

I have investigated your site and I can see why your changes does not takes place. It appears that you have used Jetpack plugin and the Photon Module is enabled. Please disable this module because this module replaces all your images with a cached version. Upon the disable of this module, the cache version should be replaced with the original or the medium and the regenerated version.

To know more about Pros and Cons of Photon module: https://jetpack.com/support/photon/

Please let us know how it goes.

Thanks, good find. I turned off Photon, cleared my browser cache and regenerated thumbnails, but they’re still the wrong size!

This feels like a never-ending problem :frowning:

Hey Alex,

Which size do you use? Is it medium size? Would you mind providing us the url of your site with login credentials so we can take a closer look? This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything.

To do this, you can create a secure note with the following info:
– Link to your site
– WordPress Admin username / password

Thank you.

Thanks. I’ve added a secure note to my post above.

I’ve had a thought – I use Cloudflare, could that perhaps be causing a caching issue?

Alex

Hey Alex,

Yes, CDN could also be the cause of the issue. Try turning it off or disconnect your site from it while we’re troubleshooting.

Thanks.

I paused Cloudflare, ensured the code was in place and regenerated all the thumbnails used in recent posts modules. But it’s still pulling in large images.

Can you please use the login info I provided in the note above to see what’s going on, because nothing has worked so far.

Alex

Hi there,

The code that you are using in the functions.php file is not working.

Please try this instead:

function x_shortcode_recent_posts_v2( $atts ) {
  extract( shortcode_atts( array(
    'id'           => '',
    'class'        => '',
    'style'        => '',
    'type'         => 'post',
    'count'        => '',
    'category'     => '',
    'offset'       => '',
    'orientation'  => '',
    'show_excerpt' => 'true',
    'no_sticky'    => '',
    'no_image'     => '',
    'fade'         => ''
  ), $atts, 'x_recent_posts' ) );

  $allowed_post_types = apply_filters( 'cs_recent_posts_post_types', array( 'post' => 'post' ) );
  $type = ( isset( $allowed_post_types[$type] ) ) ? $allowed_post_types[$type] : 'post';

  $id            = ( $id           != ''     ) ? 'id="' . esc_attr( $id ) . '"' : '';
  $class         = ( $class        != ''     ) ? 'x-recent-posts cf ' . esc_attr( $class ) : 'x-recent-posts cf';
  $style         = ( $style        != ''     ) ? 'style="' . $style . '"' : '';
  $count         = ( $count        != ''     ) ? $count : 3;
  $category      = ( $category     != ''     ) ? $category : '';
  $category_type = ( $type         == 'post' ) ? 'category_name' : 'portfolio-category';
  $offset        = ( $offset       != ''     ) ? $offset : 0;
  $orientation   = ( $orientation  != ''     ) ? ' ' . $orientation : ' horizontal';
  $show_excerpt  = ( $show_excerpt == 'true' );
  $no_sticky     = ( $no_sticky    == 'true' );
  $no_image      = ( $no_image     == 'true' ) ? $no_image : '';
  $fade          = ( $fade         == 'true' ) ? $fade : 'false';

  $js_params = array(
    'fade' => ( $fade == 'true' )
  );

  $data = cs_generate_data_attributes( 'recent_posts', $js_params );

  $output = "<div {$id} class=\"{$class}{$orientation}\" {$style} {$data} data-fade=\"{$fade}\" >";

    $q = new WP_Query( array(
      'orderby'             => 'date',
      'post_type'           => "{$type}",
      'posts_per_page'      => "{$count}",
      'offset'              => "{$offset}",
      "{$category_type}"    => "{$category}",
      'ignore_sticky_posts' => $no_sticky
    ) );

    if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();

      if ( $no_image == 'true' ) {
        $image_output       = '';
        $image_output_class = 'no-image';
      } else {
        $image              = wp_get_attachment_image_src( get_post_thumbnail_id(), 'medium' );
        $bg_image           = ( $image[0] != '' ) ? ' style="background-image: url(' . $image[0] . ');"' : '';
        $image_output       = '<div class="x-recent-posts-img"' . $bg_image . '></div>';
        $image_output_class = 'with-image';
      }

      $excerpt = ( $show_excerpt ) ? '<div class="x-recent-posts-excerpt"><p>' . preg_replace('/<a.*?more-link.*?<\/a>/', '', cs_get_raw_excerpt() ) . '</p></div>' : '';

      $output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . '" href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( sprintf( csi18n('shortcodes.recent-posts-permalink'), the_title_attribute( 'echo=0' ) ) ) . '">'
                 . '<article id="post-' . get_the_ID() . '" class="' . implode( ' ', get_post_class() ) . '">'
                   . '<div class="entry-wrap">'
                     . $image_output
                     . '<div class="x-recent-posts-content">'
                       . '<h3 class="h-recent-posts">' . get_the_title() . '</h3>'
		               . '<span class="recent-posts-author">' .the_author() . '</span>'
                       . '<span class="x-recent-posts-date">' . get_the_date() . '</span>'
                        . $excerpt
                     . '</div>'
                   . '</div>'
                 . '</article>'
               . '</a>';

    endwhile; endif; wp_reset_postdata();

  $output .= '</div>';

  return $output;

}

add_filter('wp_head', 'custom_recent_posts');

function custom_recent_posts() {
  remove_shortcode( 'x_recent_posts' );
  remove_shortcode( 'recent_posts' );
  add_shortcode( 'x_recent_posts', 'x_shortcode_recent_posts_v2' );
  add_shortcode( 'recent_posts', 'x_shortcode_recent_posts_v2' );
}

On the code, it is setting the medium size image of the featured image

$image              = wp_get_attachment_image_src( get_post_thumbnail_id(), 'medium' );

Hope this helps.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.