WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
    • Business Name Ideas
  • Deals
    • Bluehost Coupon
    • SiteGround Coupon
    • WP Engine Coupon
    • HostGator Coupon
    • Domain.com Coupon
    • Constant Contact
    • View All Deals »
  • Glossary
  • Videos
  • Products
X
☰
Beginner's Guide for WordPress / Start your WordPress Blog in minutes
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

WPBeginner» Blog» Themes» How to Automatically Link Featured Images to Posts in WordPress

How to Automatically Link Featured Images to Posts in WordPress

Last updated on July 12th, 2016 by Editorial Staff
110 Shares
Share
Tweet
Share
Pin
Free WordPress Video Tutorials on YouTube by WPBeginner
How to Automatically Link Featured Images to Posts in WordPress

Recently one of our readers asked if it was possible to automatically link featured images to blog posts in WordPress. Most WordPress themes link featured images to posts by default, but some themes may not do that. In this article, we will show you how to automatically link featured images to posts in WordPress.

Automatically link featured images to posts in WordPress

Why Link Featured Images to Posts in WordPress?

Images are more engaging than text. Using featured images can boost user engagement on your site.

Usually, featured images are large and take more space than text. They are more colorful, hence more noticeable. They are also easier to click on smaller devices like mobile phones and tablets.

List25 using featured images to engage users

However, if your post thumbnails aren’t clickable, then it makes it harder for users to view your post.

Most WordPress themes link featured images to the posts by default. Some themes may not use that approach, which makes it difficult for you to properly utilize featured images.

Having said that, let’s see how you can automatically link featured images to posts in WordPress.

Automatically Link Featured Images to Posts in WordPress

This method required you to add code into your WordPress files. See our beginner’s guide on pasting snippets from web into WordPress.

Simply add this code to your theme’s functions.php file or a site-specific plugin.

function wpb_autolink_featured_images( $html, $post_id, $post_image_id ) {
$html = '<a href="' . get_permalink( $post_id ) . '" title="' . esc_attr( get_the_title( $post_id ) ) . '">' . $html . '</a>';
return $html;
}
add_filter( 'post_thumbnail_html', 'wpb_autolink_featured_images', 10, 3 );

This code simply adds a link around the code generated to display featured images or post thumbnails on your website.

This code will also add a link around featured images on single post pages. If you don’t want to link featured images on single post to the same post, then use this code.

function wpb_autolink_featured_images( $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;

}

}
add_filter( 'post_thumbnail_html', 'wpb_autolink_featured_images', 10, 3 );

We hope this article helped you learn how to automatically link featured images to posts in WordPress. You may also want to see our list of 14 best featured image plugins and tutorials for WordPress.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

110 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • How to Fix the Error Establishing a Database Connection in WordPress

    How to Fix the Error Establishing a Database Connection in WordPress

  • Revealed: Why Building an Email List is so Important Today (6 Reasons)

    Revealed: Why Building an Email List is so Important Today (6 Reasons)

  • Checklist

    Checklist: 15 Things You MUST DO Before Changing WordPress Themes

  • How to Start Your Own Podcast (Step by Step)

    How to Start Your Own Podcast (Step by Step)

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

The Ultimate WordPress Toolkit

25 Comments

Leave a Reply
  1. Nelson Nchopereu says:
    Dec 12, 2020 at 12:25 am

    How do I put my featured image such that if the post link on WhatsApp or Facebook is shared it goes with the featured image?
    Thanks

    Reply
    • WPBeginner Support says:
      Dec 14, 2020 at 10:54 am

      For that, we cover it in our guide below that includes social meta information:

      https://www.wpbeginner.com/wp-tutorials/how-to-fix-facebook-incorrect-thumbnail-issue-in-wordpress/

      Reply
  2. Anas says:
    Dec 28, 2019 at 11:14 am

    Great Sir, Its works….

    Reply
    • WPBeginner Support says:
      Dec 30, 2019 at 11:31 am

      Thank you, glad our content was helpful :)

      Reply
  3. Rohit Sharma says:
    May 14, 2019 at 9:04 am

    How does wpbeginner design its featured images and YouTube thumbnails?
    What tools / apps / software do you use?

    They look pretty awesome..

    I couldn’t find this on your website blueprint post..so I thought of asking here..

    Waiting for your reply..!

    Reply
    • WPBeginner Support says:
      May 14, 2019 at 11:23 am

      Unless I hear otherwise, we use Camtasia for our videos and Photoshop or Affilinty designer for the article thumbnails :)

      Reply
  4. özkan says:
    Jan 26, 2019 at 3:20 pm

    Hello,

    Im so jealous of all these people that says it works.

    It doesnt work for my site. Can anybody help me about this ?

    Thank you.

    Reply
    • WPBeginner Support says:
      Jan 28, 2019 at 2:06 pm

      You may want to reach out to your theme’s support to see if there is a theme specific setting that could be overriding this.

      Reply
  5. Faizan says:
    Nov 4, 2018 at 1:59 am

    It Worked! Thanks

    Reply
  6. Carlos Alberto Romay says:
    Jun 27, 2018 at 3:32 pm

    Hi there! Awesome article, I am need to do the opposite; to discover HOW TO avoid any link from image, title or text to any url, how can I do this? I mean, you reah my website, see the blog but you CAN´t click any image, text or title, is this possible? thanks

    Reply
  7. Jennifer says:
    Jun 16, 2018 at 2:28 pm

    Hi, Thank you very much.

    I have used it in my website.

    How to add link to some thumbnails in specific size?

    Reply
  8. pete says:
    May 1, 2018 at 3:27 pm

    works for me thanks!!

    Reply
  9. Stuart Campbell says:
    Apr 20, 2018 at 8:51 am

    How can I use this method to have the featured image link to another url? What am I missing here? Thanks

    Reply
  10. Sandeep says:
    Dec 8, 2017 at 4:27 pm

    On my blog the featured images are not clickable.so it becomes a little difficult for the user to navigate to blogs.

    I think the theme whic i am using that doesn’t support that it.

    But the code you have mentioned above i will try it .
    i will try it , if it worked , that will great.

    Reply
  11. Susan Howarth says:
    Aug 31, 2017 at 9:50 pm

    Thank you so much for this!! I was worried this issue would take a lot of time and energy to figure out. After a quick copy and paste of your code, and it worked perfectly! :)

    Reply
  12. Deepak says:
    Jul 29, 2017 at 9:32 am

    it worked, i wish to know how to close the php statement ? when i use this at the end } my site gives 500 error

    Reply
  13. Ivan says:
    Jul 15, 2017 at 2:28 am

    It worked fine! Great! Thank you

    Reply
  14. modo seyoum says:
    May 19, 2017 at 11:19 pm

    i’m looking for the best way to add links to a featured image. for instance– if you click on the link below, you’ll see the header image and then two links in the content region. i’d rather have those two links appear in the header in a way that doesn’t compromise any responsive design. i have a few ideas, but i’d like to hear from a different perspective…

    Reply
  15. jeet sandhu says:
    May 17, 2017 at 1:52 am

    Hie, i have a different query. I tried displaying specific posts in specific pages using ‘post in page’ plugin. But the featured images that i have set for posts doesn’t show on the page. I mean only the title of the post is showing, but I want the featured images of all the posts to be displayed, too! Can you suggest me any way or plugin that can help me achieve this. I have searched the entire web; no one has the answer. I would be grateful if you could help me.

    Reply
  16. malik aadil says:
    Feb 19, 2017 at 8:12 am

    I am new blogger this article helped me a lot

    I was using links of in the images but the problem was Images are opening but not going to linked article

    Reply
    • WPBeginner Support says:
      Feb 20, 2017 at 1:38 am

      Hi Malik,

      We are glad you found this article helpful :) Don’t forget to follow us on Facebook for more WordPress tips and tutorials.

      Reply
  17. Sulman Qamar says:
    Jul 13, 2016 at 11:59 am

    hey dear ,
    here isn’t concerning solely featured pictures however additionally concerning committal to writing . …
    in some model that’s operating.. most of your data is nice on behalf of me and my members ..
    we follow principally .:)
    in this richest article I actually have found totally different sort of data ..
    Hope you best for your blogging future :)
    ~salman qamar

    Reply
  18. Dale Reardon says:
    Jul 13, 2016 at 8:10 am

    Hi,

    Thanks very much for this useful code.

    Is this a way (can I trouble you for the function code) to also add an ALT tag to the image link with the title of the post being linked to as the alt text?

    I’m vision impaired and at the moment the link just says the image filename which isn’t useful much of the time.

    Thanks,
    Dale.

    Reply
  19. Ankit Agarwal says:
    Jul 13, 2016 at 3:14 am

    Thanks for his tutorial. I tried this on my blog but realized that the image being shown in the thumbnail is not my featured image but the first image I am using in the post. Probably because I am using MotoPress page builder plugin. and

    There seems to be a conflict between this code and the Motopress plugin.

    Reply
  20. Dale Reardon - My Disability Matters says:
    Jul 13, 2016 at 12:43 am

    Hi,

    That worked fantastically.

    Only one further query – my website is all about disability issues:

    so I want things to be accessible and I’m blind myself so appreciate all sites doing their bit.

    Is there a way to assign ALT text to this image link composed of the title of the page it is linking to? At the moment my screen reader just reads out the picture file name which sometimes isn’t very helpful.

    Your help most appreciated.

    Dale.

    Reply

Leave a Reply Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
OptinMonster
OptinMonster
Convert website visitors into email subscribers. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 30 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2020 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2020)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2020)
    • SiteGround Reviews from 4196 Users & Our Experts (2020)
    • Bluehost Review from Real Users + Performance Stats (2020)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Create an Email Newsletter the RIGHT WAY (Step by Step)
    • Free Business Name Generator (A.I Powered)
    • How to Create a Free Business Email Address in 5 Minutes (Step by Step)
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2020 – Step by Step Guide
Deals & Coupons (view all)
PanKogut
PanKogut Coupon
Get 20% OFF on PanKogut's premium WordPress themes collection.
OptinMonster
OptinMonster Coupon
Save 10% off on OptinMonster, the best lead generation plugin for WordPress.
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).
Join our team: We are Hiring!

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
  • Free Business Tools
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • RafflePress
  • Smash Balloon

Copyright © 2009 - 2021 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

Managed by Awesome Motive | WordPress hosting by SiteGround | WordPress CDN by MaxCDN | WordPress Security by Sucuri.