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 to get permalink structure with php
- Facebook Comment Count
- PHP/Manual use of images? – 2 Questions
- How to upload imagick resource to media in wordpress
- How to use SRCSET with get_the_post_thumbnail()?
- WordPress loop specific thumbnail size
- How do I get images (with a thumbnail preview) to show in search results?
- Put a link to a category round a hard coded A HREF
- How to get Poster (thumbnail) Image of Video
- Display All Post Attachments and Assign Class to the Last Image?
- How to make thumbnail image fit into a div where image dimentions are completely different?
- Assign a picture URL to a page via PHP
- How to scale image with equal width and height without distortion?
- wordpress upgrade has broken my permalinks
- is it possible to force wordpress to always save thumbnails as ‘jpg’ not ‘png’
- How to Display Image Meta underneath EVERY image in EVERY post
- Echo URL of large version of Featured Image
- How to stop featured image thumbnail [set as background image] on blog index page just repeating same image across all posts
- Trying to add attribute to my posts’ featured image
- Recent posts with featured image or fallback image with permalink
- Randomly Assign an Image’s Alt Text Based on Data From Post
- Add prefix to link url
- WP dynamic featured image – Can’t get second featured image url
- 200 Rewrite blog post links
- PHP variable = get_the_post_thumbnail_url outputting without slashes
- php script to change slug in post automatically
- WP Post-Thumbnail
- wp_trim_words() does not work with my code Am I doing any mistake in my code?
- Changes in permalink structure in WordPress and how to apply to in-site links
- WordPress Persistent connection rule does not work for “posts”
- WordPress every page is 404 not found including admin resources
- How to use $_GET function WordPress backend
- post thumbnail, conditions, else wont work
- height should be set to auto to avoid pixelation in the post thumbnail function
- Three Questions with Twenty Eleven theme
- Display related posts without a plugin
- WordPress function and string as variable?
- Change product_base programmatically
- Divi change project category slug
- Custom post type permalinks do not appear using the link functions
- How to Handle Going Backwards in Navigation When Referrer in PHP/JavaScript won’t work?
- Remove slugs from custom posts type
- .html end of URl affected to SEO?
- Else/If Statement to Display Photo Descriptions
- How to set a featured image (thumbnail) with PHP?
- how to edit a specific post slug using a php code?
- How to replace URL protocol using PHP?
- Call featured image url
- How to pick “full/thumbnail” images in the loop?
- Creating a Category Taxonomy
- Trying to change featured image from 180×180 to full width on home page
- Insert PHP code in Text
- Permalinks: site.com/post-tite vs site.com/post-id/post-title for SEO and Speed
- Can not call .php files after switching to %postname%
- Change permalink structure specific category
- understand what code is doing when prepending /blog
- Custom URL for multiple categories hierarchy
- I can’t set image ad fatured programatically
- WordPress redirects to localhost
- 404 on old link after changing post url
- url not using query string no longer working
- Custom PHP form needs refresh to load page correctly
- Child-Theme Category View with modified permalinks (%category% removed)
- How to put 2 php codes in functions.php without site crashing
- How to add WordPress Featured image in tag ..?
- Get WordPress username to customize url
- Permalink doesn’t navigate to post (changes only url)
- 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?
- Add a default style if no Featured image is selected
- How to programmatically set existing image in media library the featured image for a post in wordpress
- 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?
- 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]
- Some links broken after updating WordPress version
- insert thumbnail image from php script
- 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
- Multiple URL from Custom post name
- Overwriting a Shortcode
- Setting post thumbnail sizes in template file and functions.php
- Get permalink for a post from inside WordPress and route to a related site
- 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?
- WordPress add parameters with friendly url structure
- Remove default Image Sizes
- Add attribute to featured image with filter (wp_get_attachment_image_attributes)