• Hi all,

    I’m using the theme “Shuttershot”. When I make a blog post, but I don’t set a featured image, it just shows a blank image.
    I realise this is because it’s using fall back/default image instead. What I’d like to do is have it so that if there’s no featured image uploaded, it doesn’t show an image.

    The code I’m working with is:

    <div class="entry">
    
    <?php
    if ( has_post_thumbnail() ) { ?>
    	<a href="<?php the_permalink() ?>"><img class="postimg" src="<?php bloginfo('stylesheet_directory'); ?>/timthumb.php?src=<?php get_image_url(); ?>&h=200&w=470&zc=1" alt=""/></a>
    <?php } else { ?>
    	<a href="<?php the_permalink() ?>"><img class="postimg" src="<?php bloginfo('template_directory'); ?>/images/dummy.png" alt="" /></a>
    <?php } ?>
    <?php the_excerpt(); ?>
    <div class="clear"></div>
    </div>

    I’ve had a look at the documentation, but it didn’t seem to help. Unfortunately, my knowledge of PHP is seriously lacking.

    I initially thought that if I just removed the “else” code, then it would work, but it didn’t appear to. Unless I didn’t remove enough/the right bit?

    Anyway, hopefully that makes sense.

    Thanks in advance,
    Will.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi William-C,

    This forum only supports themes from the wordpress.org theme repository. Shuttershock is a commercial theme, so you’ll be able to get specific help from the theme developers. Try here! There are likely custom things going on in the theme that we wouldn’t know about.

    Thread Starter William-C

    (@william-c-1)

    Thanks for the reply, but it’s not specifically that theme that’s the issue; it’s a general WordPress/PHP question. It just so happens I want to implement it in a different theme.

    So, thanks anyway, but would anyone be able to answer my question?

    Thanks in advance,
    Will

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Nothing is wrong with your code, what is likely to be the issue is that your theme implements the featured image differently to the Codex example.

    Thread Starter William-C

    (@william-c-1)

    So, I was right in assuming I just had to remove this code:

    <?php } else { ?>
    	<a href="<?php the_permalink() ?>"><img class="postimg" src="<?php bloginfo('template_directory'); ?>/images/dummy.png" alt="" /></a>
    <?php } ?>
    <?php the_excerpt(); ?>
    <div class="clear"></div>

    And, in theory, that would cause the featured image to be removed when I haven’t selected one?

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘If No Featured Image’ is closed to new replies.