• Hi All,

    I have had a browse around the web and managed to find some code to add a default image when no featured image has been set but I am a struggling a little to implement it to the below code.

    In effect, I have imported a blogroll from Joomla and there are over 100 entries without any featured image or thumbnails so I would like to add a default image (blog_default.jpg) when nothing has been set as the featured.

    <div class="feat_img">
                  <?php
    $thsrc = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'medium', false, '' );
    $fullsrc = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full', false, '' );
    echo ('<a href="'.$fullsrc[0].'"><img src="'.$thsrc[0].'"/></a>'); ?>
                </div>

    I hope you can help – Thanks in advance

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter robbiebrown34

    (@robbiebrown34)

    Any ideas?

    <div class="feat_img"><?php
    if( wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail', false ) ) the_post_thumbnail();
    else echo '<img src="' . get_stylesheet_directory_uri() .'/images/blog_default.jpg" width="xx" height="yy" alt="" />';?>
    </div>

    The above, untested, code should output a post thumbnail (if is there is one). If there isn’t, it will display the blog_default.jpg image that is within your current theme’s images folder.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Default Thumbnail/default image when empty’ is closed to new replies.