How to Link Featured Images to Posts in Twenty Twenty Theme

In this very quick tutorial, I’ll help you to make the featured image links to the post.

So you’re using Twenty Twenty theme and in your category archive pages or in your blog pages the featured image does not link to the post. Well, in this very quick tutorial, I’ll help you to make the featured image links to the post.

What you need?

  • A child theme: if you’re using Twenty Twenty theme, the parent, most likely you’ll lose the fix I explain here with the next theme update. You’ll need a child theme which is, by the way, recommended when you do any kind of edits to your theme. You can download Twenty Twenty child theme I created. You can read more about it here.
  • An FTP access to your site to make the changes. If you have not disabled the theme editor, you can apply the fix directly by going to Appearance -> Theme Editor, it’s not recommended to keep the theme editor enabled though.

Let’s Do it!

To make the featured image links to the post, go ahead and add the following code to your child theme’s functions.php file.

add_filter( 'post_thumbnail_html', 'twentytwenty_featured_image_link', 10, 3 );
function twentytwenty_featured_image_link( $html, $post_id, $post_image_id ) {

	if (! is_singular()) {
		$html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_the_title( $post_id ) ) . '">' . $html . '</a>';
		return $html;
	} else {
		return $html;
	}
}

شارك هذه المقالة:

Facebook
Twitter
LinkedIn
Reddit

إقرأ أكثر عن ووردبريس

اترك تعليقاً

لن يتم نشر عنوان بريدك الإلكتروني. الحقول الإلزامية مشار إليها بـ *