1

For some reason is_front_page isn't triggered on my subsite, running a child theme with its own header with a page set as a static home page under Reading.

I have this code in header.php to control which metatags to show on a post/page or on the frontpage, but only the is_single / is_page is printed.

<?php if (is_single() || is_page()) : if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

<!-- this is printed -->

<?php endwhile; endif; elseif(is_home() || is_front_page()) : ?>
<!--this is not printed -->

<?php endif; ?>

I was wondering if the is_page and is_front_page are cancelling each other out since they are both true when using a static front page?

1

Indeed, if your site has a static page on the front, the condition is_page will be true and WP will never get to the elseif.

If you want a different template for your front page, you should exclude it from the first condition so it will return false in that case. Like this:

if ((is_single() || is_page()) && !is_front_page())

Or you can switch the statements around: first test for home/front and if that fails for single/page.

  • 1
    Thank you! Yes, we need to restructure that code a bit. – Morten Skogly Sep 1 '16 at 8:02

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.