Set a Default Featured Image for your Posts in WordPress

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.



Do you need help with a project? or have a new project in mind that you need help with?

Contact Me