WordPress custom fields if ifelse else condition

I’d like to implement an if – ifelse – else condition.

  • if condition is for posts having an image (standard)
  • ifelse condition is for video-posts without images. I added a custum field to upload a videostill-image to be shown as thumbnail in the news-section on frontpage instead.
  • else is the fallback image for posts without any image

I tried the following but it doesn’t work and my php-skills are rudimentary. Here’s a link to the section: http://parkfreunde-weissensee.berlin/#news

        <div class="list-article-thumb-mobile">
            <a href="<?php echo esc_url( get_permalink() ); ?>">
                if ( has_post_thumbnail( ) ) {
                    the_post_thumbnail( 'onepress-blog-small' );

                elseif ( get_field ( 'post_thumbnail_home' ) ) {
                    the_field ( 'post_thumbnail_home' );

                else {
                    echo '<img alt="" src="'. get_template_directory_uri() . '/assets/images/placholder2.png' .'">';

Read more here: WordPress custom fields if ifelse else condition

Leave a Reply

Your email address will not be published. Required fields are marked *