Setup A Default Featured Image

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.

Related posts

Leave a Reply

3 comments

  1. 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.

  2. while you say you’d like to use a plugin … there is a very easy method to do what you want

    basically inside your theme folder you will want to open and edit a file called single.php

    you want to look for this code

    the_post_thumbnail();
    

    and replace it with this code (changing the path_to/default_image.jpg)

    <?php if ( has_post_thumbnail() ) {  
    the_post_thumbnail();  
    } else { ?>  
    <img src="<?php bloginfo('template_directory'); ?>/images/default-image.jpg" alt="<?php the_title(); ?>" />  
    <?php } ?>`
    

    If you find your site breaks / page doesn’t load then you may need to remove the the opening

    <?php and closing   ?>  
    

    source: http://www.wpbeginner.com/wp-themes/how-to-set-a-default-fallback-image-for-wordpress-post-thumbnails/

    Hope that helps?

    Cheers

    Damien