0

How do I find out if the archive is a post format, like 'gallery' (www.example.com/type/gallery/)?

I can use is_archive() and and is_search() for those.

Is there something like is_type() or is_format()?

1 Answer 1

0

You can use has_post_format to check the if the post format equal to some format type.

From the docs

if ( has_post_format('gallery') ) {
    // Do something
 }

Or use $format = get_post_format() and then do some condition..

$format = get_post_format();
if ( $format == 'gallery' ) {
    // Do something
 }

If you want to use it outside the loop there is a problem with this method. because it check if the first post is in the format.

So its could return false positive if you are in category page when the first post has the post format too.

For outside the loop you can check for the get_queried_object

$queried_object = get_queried_object();
if($queried_object->taxonomy == 'post_format' && $queried_object->name == 'Gallery') {
    // Do something
}

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.