I’m trying to setup a default fallback featured image on my website to ensure consistency with images being displayed for every post, even when an image is not embedded in the post. I’ve tried a number of plugins – Default Post Thumb and Default Thumb, however neither of these seemed to work. I’m using WP 3.4 and the Suffusion Theme 4.2.2 on the site which can be seen at http://www.aliveradio.net/ I’m not very capable at editing basecode and would prefer to work with plugins, however if anyone could help with code alterations I’d be happy to give it a go.

Thank-you in advance for any help you can provide.

3 Answers
3

One simple method is to filter post_thumbnail_html, to add in a default image link:

<?php
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' );
?>

You can make this filter more complex, but this should get you started.

Leave a Reply

Your email address will not be published. Required fields are marked *