WordPress Default Featured Image

I’ve got a WordPress site and have added the following code to the Single.php file, which means if I publish a blog post without selecting a ‘Featured Image’, it will display a default ‘Featuered Image’ instead (tellymedia-temporary-image.jpg).

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

This works fine on the actual page displaying the individual blog post (which shows the default image), but I’m also using the following code in my Functions.php file, to display a ‘Featured Image’ thumbnail for each post in the Sidebar:

Read More
<a href="<?php the_permalink(); ?>"><span class="widget-listing-thumbnail"><?php the_post_thumbnail(); ?></span><?php get_the_title() ? the_title()+the_subtitle('<span class="widget-subtitle">', '</span class="widget-subtitle">') : the_ID(); ?></a>

While this works for all other posts it doesn’t work for any where I haven’t selected a ‘Featued Image’. Is there a way to tweak the code in my Functions.php file please, so it will also display a thumbnail of the default ‘Featuered Image’ in the Sidebar for posts where I haven’t selected one please?

Thanks!

Related posts

Leave a Reply

1 comment

  1. try this one.

    <a href="<?php the_permalink(get_the_id()); ?>">
        <span class="widget-listing-thumbnail">
        <?php if ( has_post_thumbnail() ) {
            the_post_thumbnail();
        } else { ?>
            <img src="<?php bloginfo('template_directory'); ?>/branding/tellymedia-temporary-image.jpg" alt="<?php the_title(); ?>" />
        ?>
        </span>
        <?php get_the_title() ? the_title() + the_subtitle('<span class="widget-subtitle">', '</span class="widget-subtitle">') : the_ID(); ?>
    </a>