0

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.

1

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';
  }

}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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