One of the key things we focus on here at WPBeginner is making sure every post has an eye-catching featured image. After all, a post without a featured image can look incomplete and unprofessional.
Featured images help your WordPress posts grab attention. They make your content more appealing and get more clicks when shared on social media. But let’s be honest, creating a unique image for every post takes time, and sometimes you just need to publish quickly.
That’s why having a default fallback image is so helpful. It keeps your site looking clean and professional, even when you’re in a hurry.
In this guide, we’ll show you three easy ways to set up a default fallback image for your WordPress posts. We’ll cover both plugin and code methods, so you can choose what works best for you.
Why Set a Default Featured Image in WordPress?
In WordPress, featured images (or post thumbnails) are very important visual elements that represent your content.
They grab attention on your blog, in archives, and on social media, giving readers a quick preview of what to expect.
But what happens when you don’t have this WordPress design element for every post? That’s where setting a default featured image comes in handy.
This solution is perfect for busy news sites, older content without images, or maintaining a consistent branded look across your WordPress website.
Without a default image, your site might look odd. Posts without images can stand out in a bad way, making your site look messy. This can confuse readers and make your site seem less professional.
With that in mind, let’s look at 3 easy ways to set up a WordPress default post thumbnail for your posts. You can use the quick links below to skip to your preferred method:
Method 1: Add a WordPress Default Featured Image With a Plugin
This method is perfect for beginners as it doesn’t require any coding. We will use the Default Featured Image plugin to show a default fallback WordPress post thumbnail.
First, install and activate the Default Featured Image plugin on your WordPress site. If you’re not sure how to do this, check out our beginner’s guide on installing WordPress plugins.
Once activated, go to Settings » Media in your WordPress dashboard. You’ll see a new option to ‘Select default featured image’. Click this button to open your media library.
Here, you can choose an existing image or upload a new image to use as your fallback for posts.
After selecting your image, you’ll notice options to set maximum dimensions for your default featured image sizes.
You can adjust these if you want or leave them as they are if you’re happy with the default settings.
When you’re done, scroll down and click ‘Save Changes’. To see your changes in action, preview your website on both mobile and desktop.
Now, whenever you create a post without setting a featured image, your WordPress site will automatically use this fallback image as the post thumbnail.
Method 2: Set a Default Fallback Featured Image With Code
If you’re comfortable with coding or prefer not to use the other plugin, then you can set a fallback post thumbnail image manually.
We will use the WPCode plugin to add this functionality safely and easily.
First, install and activate the WPCode plugin on your WordPress site. If you need help, check our guide on installing WordPress plugins.
Once activated, go to Code Snippets » + Add Snippet in your WordPress dashboard. Choose ‘Add Your Custom Code (New Snippet)’ and click ‘+ Add Custom Snippet’.
Now, name your snippet something like ‘Set Fallback Image for Posts Without Featured Images’.
Also, change the Code Type to ‘PHP Snippet’.
Next, paste the provided code into the Code Preview box:
function set_default_featured_image( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
if ( empty( $post_thumbnail_id ) ) {
// Replace ‘http://example.com/path/to/your/default-image.jpg’ with the URL of your default image.
$default_image_url = ‘http://example.com/path/to/your/default-image.jpg’;
$html = ”;
}
return $html;
}
add_filter( ‘post_thumbnail_html’, ‘set_default_featured_image’, 10, 5 );
function set_default_featured_image_url( $url, $post_id ) {
if ( empty( get_post_thumbnail_id( $post_id ) ) ) {
// Replace ‘http://example.com/path/to/your/default-image.jpg’ with the URL of your default image.
$url = ‘http://example.com/path/to/your/default-image.jpg’;
}
return $url;
}
add_filter( ‘default_post_thumbnail_url’, ‘set_default_featured_image_url’, 10, 2 );
This code does two main things. First, it sets a default image to display when a post doesn’t have a featured image.
Second, it ensures that this default featured image is used consistently across your site, including in places where only the image URL is needed.
You’ll need to replace the example image URL in the code with the URL of your chosen default image (see the highlighted parts of the code sample).
If you’re not sure how to get the URL of your image, check out our article on how to get the URL of images you upload in WordPress.
After pasting the code, scroll down to the Insertion section. Keep the Insert Method as ‘Auto Insert’ and change the Location to ‘Frontend Only’.
Finally, toggle the button at the top right to ‘Active’ and click ‘Save Snippet’.
When you view your blog homepage now, you should see your default image appearing for any posts that don’t have a featured image set.
Method 3: Set the First Image as Post Thumbnail With Code
This method automatically uses the first image in your post as the thumbnail. It’s a great option if you always include images in your posts and want to save time by not setting featured images manually.
We’ll use the WPCode plugin again for this. If you haven’t installed it yet, then follow our beginner’s guide on installing WordPress plugins.
After activating WPCode, go to Code Snippets » + Add Snippet in your WordPress dashboard. Choose ‘Add Your Custom Code (New Snippet)’ and click ‘+ Add Custom Snippet’.
At this stage, you can name your snippet something like ‘Use First Image in Post as Featured Image’.
Then, change the Code Type to ‘PHP Snippet’.
Next, paste the following code into the Code Preview box:
// Function to get the first image from the post content
function get_first_image_from_content( $post_content ) {
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($post_content);
libxml_clear_errors();
$xpath = new DOMXPath($dom);
$image_nodes = $xpath->query(“//img”);
if ( $image_nodes->length > 0 ) {
$image_url = $image_nodes->item(0)->getAttribute(‘src’);
return $image_url;
}
return false;
}
// Function to set the first image as the featured image
function set_first_image_as_featured( $post_id ) {
if ( wp_is_post_autosave( $post_id ) || wp_is_post_revision( $post_id ) ) {
return;
}
if ( has_post_thumbnail( $post_id ) ) {
return;
}
$post = get_post( $post_id );
if ( ! $post ) {
return;
}
$image_url = get_first_image_from_content( $post->post_content );
if ( $image_url ) {
$upload_dir = wp_upload_dir();
if ( false !== strpos( $image_url, $upload_dir[‘baseurl’] ) ) {
$attachment_id = attachment_url_to_postid( $image_url );
if ( $attachment_id ) {
set_post_thumbnail( $post_id, $attachment_id );
}
}
}
}
add_action( ‘save_post’, ‘set_first_image_as_featured’ );
// Function to filter the post thumbnail HTML
function filter_post_thumbnail_html( $html, $post_id, $post_thumbnail_id, $size, $attr ) {
if ( ! $html ) {
$post = get_post( $post_id );
if ( $post ) {
$image_url = get_first_image_from_content( $post->post_content );
if ( $image_url ) {
$html = ”;
}
}
}
return $html;
}
add_filter( ‘post_thumbnail_html’, ‘filter_post_thumbnail_html’, 10, 5 );
Simply put, this code looks for the first image in your post content. If it finds an image and there’s no featured image set, then it makes that first image the featured image.
This code works automatically whenever you save or update a post. It only sets a new featured image if one isn’t already set, so it won’t override any featured images you set manually.
Once done, scroll down to the Insertion section. Make sure to keep the Insert Method as ‘Auto Insert’ and the Location as ‘Run Everywhere’.
Lastly, toggle the button at the top right to ‘Active’ and click ‘Save Snippet’.
When you view your blog homepage now, you should see the first image from each post being used as its thumbnail.
Like so:
Bonus: Essential WordPress Image Tips
Now that you’ve learned how to set default fallback images for your post thumbnails, here are some other useful image-related techniques for WordPress:
We hope this article has helped you learn how to set a default fallback image for WordPress post thumbnails. You may also want to check out our expert picks of the best drag-and-drop page builders for WordPress and our ultimate guide on how to edit a WordPress website.
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.