I have updated your code so that the fallback image has post permalink. I hope this helps:
if ( has_post_thumbnail() ) {
echo '<a href="' . get_permalink($post->ID) . '" >';
the_post_thumbnail();
echo '</a>';
} else {
echo '<a href="' . get_permalink($post->ID) . '" ><img src="'. get_stylesheet_directory_uri() . '/img/fallback-featured-image.jpg" /></a>';
}
Related Posts:
- How to get URL of current page displayed?
- How do I change/modify the_post_thumbnail(); html output?
- What’s the best way to use the Featured Image for responsive web design?
- Disable Attachment Pages Completely
- how to get permalink structure with php
- Facebook Comment Count
- PHP/Manual use of images? – 2 Questions
- Adding Featured Image to Post programatically
- How to Remove Parents Category Permalink from Posts
- How to upload imagick resource to media in wordpress
- How to add a featured image to a existing post via php?
- How to use SRCSET with get_the_post_thumbnail()?
- add_rewrite_rule with bottom priority doesn’t handle the WordPress pages
- Adding featured image via PHP
- WordPress loop specific thumbnail size
- How do I get images (with a thumbnail preview) to show in search results?
- Rewrite rule not working, but only when parameter is text
- How to put 2 php codes in functions.php without site crashing
- How to add WordPress Featured image in tag ..?
- How does Permalink work with the AMP plugin after Removing Parent Permalink Catalog from Posts
- Get WordPress username to customize url
- Permalink doesn’t navigate to post (changes only url)
- Post permalink buttons all going to the first post
- WordPress generate images size after upload
- Permalink changes after several minutes after saving post
- How to edit button permalink inside function.php using a child theme?
- WordPress/NGINX not respecting the category URL for new posts
- Add a default style if no Featured image is selected
- WordPress generates weird permalinks
- How to link all featured images to custom url in single.php for only non-logged-in users?
- How to programmatically set existing image in media library the featured image for a post in wordpress
- Permalink like example.com/taxonomy/post_type/postname
- Having trouble with customizing blog posts on the home page
- How do I stop my form from adding code to current page URL instead of re-directing. Been stuck for days
- image on homepage disappeared due to change of permalink name
- How to link featured images in single.php for only non-logged-in users?
- Thumbnail wouldn’t scale to size properly
- Custom content using in_category
- What is the proper way to call a function (from functions.php) on a link click?
- How do I generate formatted permalinks as specified in backend options?
- 403 Forbidden Localhost Wamp Apache Php
- get_post_thumbnail_id returns a negative number
- redirect 301 with special character like WIX site “#!”
- Permalinks and custom PHP application
- Basic PHP question (displaying post title over thumbnail) [closed]
- Showing featured image of page’s child’s children page
- How to solve 404 permalink errors on nginx server
- Some links broken after updating WordPress version
- insert thumbnail image from php script
- add_rewrite_rule questions
- Can’t put a hyperlink on Featured Post’s Image
- add class to background image
- Weird slug in archives permalink
- WordPress Rewrite Issue
- Would it be possible to route WordPress Through an MVC Application
- News and Featured image
- How to correctly add the featured immage (thumbnails) support in a WP theme? Why I can’t add a featured immage?
- Newly published content gives 404 on wordpress
- set new link as permalink
- Multiple URL from Custom post name
- echo variable containing html and the_permalink();
- Overwriting a Shortcode
- featured post as div background
- How to display thumbnail if post is assigned one otherwise not
- Post Thumbnail on Single (if elseif else)
- append links with unique number string
- the_post_thumbnail unless video id is added
- get_permalink returning first letter
- Setting post thumbnail sizes in template file and functions.php
- Get permalink for a post from inside WordPress and route to a related site
- custom data in url
- Make a permalink to the most recent blog post
- PHP code for link with text
- Remove /category/ from category (archive) page URLs (without using a plugin)
- Accessing WordPress Functions get_permalink() in Vanilla PHP?
- How can i give a download link to the thumbnail or featured image
- add if statement to the featured image
- How to crop featured image in different sizes?
- WordPress add parameters with friendly url structure
- Remove default Image Sizes
- Add any username as link prefix and show data from that specific user’s profile on wordpress pages – with no login required
- Add attribute to featured image with filter (wp_get_attachment_image_attributes)
- Generate and upload screenshot as featured image for user-submitted post
- how to goto specific page number including title with permalink
- How to extract URLs from wordpress taxonomies
- WordPress 6.1.1 UTF8 Slug Limit Increase
- why css file not link?how to create permalink?
- How to automatically flush permalinks?
- Execute wp_after_insert_post after the permalink is customized
- WordPress CPT & Custom Taxonomy with the SAME Permalink Structure
- Remove slug of multiple custom post types with and without hierarchical
- Modify the permalink structure for a specific category
- change the blog in the url if you go from a specific page wordpress
- Is it possible to go to the next post in the same category?
- Restricting Image Upload Sizes using ‘wp_handle_upload_prefilter’ – Stuck media progress bar when Featured Image?
- WordPress per ACF – permalink is not working
- Processing data and redirecting with query string
- I’ve added SKU to Woocommerce permalinks, but I have small issue
- Post returns 404 after changing the permalink using post_type_link
- Cannot access the other pages after successfully editing post type