• Resolved foochuck

    (@foochuck)


    I’d like to put a code in my header.php file that will detect what page template is being used.

    For example I have two page templates:

    page-template-1.php
    page-template-2.php

    If page-template-1.php I would like to display menu 1 in header.php and if page-template-2.php is being used I would like to display menu 2 in header.php

    Can anyone set me in the right direction for the code to use in header.php to detect the page template?

    Thanks!

    -foo

Viewing 3 replies - 1 through 3 (of 3 total)
  • <?php
    
    if ( is_page_template('page-template-1.php') ) {
    
    stuff
    
    } elseif ( is_page_template('page-template-2.php') ) {
    
    different stuff
    
    }
    
    ?>
    Thread Starter foochuck

    (@foochuck)

    Awesome. Thank you @rev. Voodoo!

    Thread Starter foochuck

    (@foochuck)

    One other question on this topic – how can I do the same thing to test what page is currently being used? Would I need to test the page ID or page title?

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Detecting Page Template in Header.php’ is closed to new replies.