How to set the default fallback image for WordPress post thumbnails? Let’s use this article to find a solution. As part of our WordPress Support Services, Bobcares provides answers to WordPress-related questions.
How to set the default fallback image for WordPress post thumbnails?
Post thumbnails, often known as featured pictures, are a WordPress theme feature that allows users to link an image to a blog post or article. This image is then placed on the homepage, archives, or sidebar widgets, depending on the theme. If we forget to add one, then the article will appear without the image. Hence the layout will look broken.
The default fallback image prevents such situations and it will be used when no post thumbnail is found. Let’s look at how to easily configure a default fallback image for WordPress post thumbnails.
Solution 1
- Firstly, download and install the WordPress Default Featured Image plugin.
- Go to the Settings » Media page to customize the plugin settings.
- Click the ‘Select default featured image’ option on the new page to upload or select the image we want to use as the fallback post thumbnail.
- Click on the Save changes button.
- Finally, we can visit the website to see it in action.
Solution 2
In this method, we are using codes on the WordPress theme files. The following are the steps to set the default fallback image for WordPress post thumbnails:
- Firstly, create an image that we need to use as the default image.
- Then upload it to the WordPress theme’s images folder using any FTP client. The images folder for the theme is placed in the /wp-content/themes/yur-theme/ folder. If it does not have an images folder, we must create one.
- When a post does not have its own post thumbnail, tell WordPress to look for this image. Post thumbnails are displayed in many locations across the WordPress theme. In the theme files, check for the_post_thumbnail() method. It’s usually found in archive.php, single.php, or content templates.
Next, include the below code where we want to display the thumbnail.
<?php if( has_post_thumbnail() ) {the_post_thumbnail();} else{ ?><img
src=”<?php bloginfo(‘template_directory’); ?>/images/default-image.jpg”alt=”<?
php the_title(); ?>”/><?php } ?>
- Also, replace default-image.jpg with our own image file name.
- Finally, we can visit the website to see it in action.
[Searching a solution for a different WordPress issue? We’re here to assist.]
Conclusion
To summarize, we have included two solutions from our Tech team to set up the default fallback image for WordPress post thumbnails.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
var google_conversion_label = "owonCMyG5nEQ0aD71QM";
0 Comments