I am using Oxygen to build a search results page. I am very new to CSS and PHP editing. I just floated an image right for the first time. So please forgive my ignorance.

I want to stop the thumbnail placeholder appearing in the search results when the post does not have a thumbnail/feature image set. I know that function that gets the image is <?php echo get_the_post_thumbnail_url(); ?> but I have no clue how I would write the code to say if the post thumbnail is false (? maybe) then don't display the thumbnail.

Is anyone available to help me? I would be most appreciative.

I've copied the code I am using below and here's a screenshot of the Oxygen editor.

enter image description here

I am using this code in the Oxygen Template editor.

<div class='oxy-post'>
    <a class='oxy-post-image' href='<?php the_permalink(); ?>'>
      <div class='oxy-post-image-fixed-ratio' style='background-image: url(<?php echo get_the_post_thumbnail_url(); ?>);'>
      <div class='oxy-post-image-date-overlay'>
        <?php the_time(get_option('date_format')); ?> <?php the_title(); ?> 

    <a class='oxy-post-title' href='<?php the_permalink(); ?>'><?php the_title(); ?></a>

    <div class='oxy-post-meta'>
        <div class='oxy-post-meta-author oxy-post-meta-item'>
            <?php the_author(); ?>

        <div class='oxy-post-meta-comments oxy-post-meta-item'>
            <a href='<?php comments_link(); ?>'><?php comments_number(); ?></a>

    <div class='oxy-post-content'>
        <?php the_excerpt(); ?>
    <a href='<?php the_permalink(); ?>' class='oxy-read-more'>Read More</a>

1 Answer 1


This below if statement checks to see if there is a thumbnail in the post. If not, nothing will display.

if ( has_post_thumbnail() ) {     
    echo '<div class="oxy-post-image-fixed-ratio" style="background-image: url('.get_the_post_thumbnail_url().')"></div>';
  • Thanks Tanmay - I tried that but I get a server error. I am a complete newbie so do I just copy your code in place of the current php tag? I tried that and got a server error.
    – Pat Birgan
    Mar 19, 2021 at 5:15
  • @PatBirgan I have updated above code. so please try it again. Mar 19, 2021 at 5:24
  • Here's a screenshot. imgur.com/waMw7vK Now the thumbnail names is overlaid on top of the thumbnail but the thumbnail still appears when none are set
    – Pat Birgan
    Mar 19, 2021 at 5:30
  • you have wrote 2 times same divs one I have wrote in my code and one you have already written in your code so just replace this your code <div class='oxy-post-image-fixed-ratio' style='background-image: url(<?php echo get_the_post_thumbnail_url(); ?>);'> </div> to my updated above code Mar 19, 2021 at 5:35
  • @PatBirgan you can replace this red marker code prnt.sc/10pmcln to my above updated code. Mar 19, 2021 at 5:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.