is_page_template not working as expected

I’m trying to serve different headers based on what type of page the user is on. This is my code.

<!-- IF HOME -->
        <?php if ( is_front_page() && is_home() ) : ?>
        <?php get_template_part( 'template-parts/headers/home-header' ); ?> 

        <!-- IF TEMPLATES -->

        <?php elseif ( is_page_template('archive-mobile_photo.php') ) : ?>
        <?php get_template_part( 'template-parts/headers/home-header' ); ?> 

        <!-- IF  POST -->
        <?php else : ?>
        <?php get_template_part( 'template-parts/headers/zine-header' ); ?>     

        <?php endif; ?>

What’s weird is that the homepage and post pages are working fine, but the check using is_page_template() isn’t working. I have the query monitor plugin and it’s confirming the page is the archive-mobile_photo.php template.

I’m pretty new to WordPress and I’m at a total loss.

2 Answers
2

It looks like you’re checking if you’re on the mobile_photo post type archive with this line:

<?php elseif ( is_page_template( 'archive-mobile_photo.php' ) ) : ?>

If that’s indeed the case, use is_post_type_archive( $post_types ) instead:

<?php elseif ( is_post_type_archive( 'mobile_photo' ) ) : ?>

Leave a Comment