I need to get different template parts when locating on different pages, for e.g. Homepage.

<?php if (is_home()) {
  get_template_part( 'partials/hp-header' )
    } else {
        get_template_part( 'partials/single-page-header' )};
  • What's your question? What's not working and the expected outcome? – Sally CJ Oct 29 '20 at 13:15
  • The code seems to not work for me, so I'm trying to figure out what is wrong with it. – Anderson Oct 29 '20 at 13:36
  • Where do you put the code - in what template? And how does it not working - the template part being loaded is not the right one? Are you sure the template parts (e.g. partials/hp-header.php) exist? And how about trying a simple echo test - if ( is_home() ) echo 'hp-header'; else echo 'single-page-header'; ? – Sally CJ Oct 29 '20 at 14:00

Your Answer

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

Browse other questions tagged or ask your own question.