Set a Default Featured Image for your Posts in WordPress

Date Posted: May 28, 2014, 7:39 am


Simply add the following code to your functions.php

1
2
3
4
5
6
7
8
9
10
function wpse55748_filter_post_thumbnail_html( $html ) {
    // If there is no post thumbnail,
    // Return a default image
    if ( '' == $html ) {
        return '<img src="' . get_template_directory_uri() . '/images/default-thumbnail.png" width="150px" height="100px" class="image-size-name" />';
    }
    // Else, return the post thumbnail
    return $html;
}
add_filter( 'post_thumbnail_html', 'wpse55748_filter_post_thumbnail_html' );

Be sure to replace the default-thumbnail.png with your desired default post thumbnail and adjust the width and height.

About author


Carl Victor Fontanos

A fine gentleman specializing in front-end and back-end development with extensive experience building high performance web applications that keeps users engaged and help businesses grow.

 
Hire Me