• I have a few defined post thumbnail sizes, and I want a check performed to say, “if SQUARE size, show that, then if not, show default Post Thumbnail”.. but this below doesnt seem to work:

    <?php if(has_post_thumbnail('square')) { ?>
        <?php the_post_thumbnail('square'); ?>
    <?php } elseif(has_post_thumbnail()) { ?>
      <?php the_post_thumbnail(); ?>
    <?php } >

    Even though the SQUARE size exists, it just shows the normal size defined by the post thumbnail default setting. How do I get it to display the square image first, if it exists?

Viewing 2 replies - 1 through 2 (of 2 total)
  • I think the problem may be that the square was defined after the image was uploaded to the system. If that’s the case you could use something like Regenerate Thumbnails to regen all your images which will run for custom sizes and normal sizes, neat plugin.

    If you’re really deadset on this kind of solution, maybe check out this answer on the WordPress Stack Exchange by trewknowledge

    The problem is that has_post_thumbnail() takes the ID of a post, not a thumbnail size. So passing in a size (like ‘square’) will always return false becuase there’s no post with the ID of ‘square’.

    What you want isn’t really something supported by WordPress. The system pretty much expects that every size image will be available, and if no tit will default to the full-sized image.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘how to check if particular post thumbnail exist, display that one’ is closed to new replies.