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?
- how to get permalink structure with php
- PHP/Manual use of images? – 2 Questions
- How to Remove Parents Category Permalink from Posts
- How to upload imagick resource to media in wordpress
- 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?
- fallback image for featured image
- Put a link to a category round a hard coded A HREF
- 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 is WordPress manipulating the posts like there are folders?
- How to scale image with equal width and height without distortion?
- wordpress upgrade has broken my permalinks
- How can I add pagination and how can I change thumbnail size?
- Do changes to WordPress permalink custom structure affect old urls?
- WordPress custom slug (endpoint) and compare all links
- 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
- Add prefix to link url
- Set the background to a default image if there isn’t a specified “featured image”
- PHP variable = get_the_post_thumbnail_url outputting without slashes
- php script to change slug in post automatically
- WordPress every page is 404 not found including admin resources
- WordPress returning 404 for multisite pages
- 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
- How to get post permalink url without a href
- WordPress function and string as variable?
- Resize image to specific dimension (X to Y ratio)
- Change product_base programmatically
- Divi change project category slug
- Using featured image of blog archive page
- 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 replace URL protocol using PHP?
- Call featured image url
- 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
- Need to add a post’s featured image to a section on the frontpage
- 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
- not outputting medium size image URL
- How to put 2 php codes in functions.php without site crashing
- How to add WordPress Featured image in tag ..?
- 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
- Custom content using in_category
- 403 Forbidden Localhost Wamp Apache Php
- get_post_thumbnail_id returns a negative number
- Permalinks and custom PHP application
- Basic PHP question (displaying post title over thumbnail) [closed]
- How to solve 404 permalink errors on nginx server
- Some links broken after updating WordPress version
- insert thumbnail image from php script
- add class to background image
- WordPress Rewrite Issue
- Would it be possible to route WordPress Through an MVC Application
- News and Featured image
- featured post as div background
- 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
- Accessing WordPress Functions get_permalink() in Vanilla PHP?
- Remove default Image Sizes
- 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
- Modify the permalink structure for a specific category
- Restricting Image Upload Sizes using ‘wp_handle_upload_prefilter’ – Stuck media progress bar when Featured Image?
- I’ve added SKU to Woocommerce permalinks, but I have small issue