display post format text in loop

If post format is Gallery or another then echo my custom text. Get post format from post id. I want to do like this code in wordpress post loop

if (isset(get_post_format(gallery))){
echo 'Gallery';
}

Thanks.

Topic post-formats loop gallery Wordpress

Category Web


get_post_format() returns the post format slug for either the current post, when used inside a loop, or a given post, when a WP_Post object or an integer post ID is passed to it as a parameter.

So, if you're using the function in a posts loop, then you can use it like this,

while ( have_posts() ) {

  the_post();

  if ( 'gallery' === get_post_format() ) {
    echo 'Gallery';
  } else {
    echo 'Not Gallery';
  }

}

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.