Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How do I call a different header files in WordPress. For example, I made ​​a wordpress theme with a variety of different display header. There header1.php, header2.php, header3.php, header4.php, header5.php. As shown below.


Header Layout


So I want to call any of the headers in the Appearance> Menus in WordPress.

This is the code that I have created:


<?php
    if($options['header_style']) {
        if(is_page('header2')) {
            include_once('inc/header/header2.php');
        } elseif(is_page('header3')) {
            include_once('inc/header/header3.php');
        } else {
            include_once('inc/header/header'.$options['header_style'].'.php');
        }
    } else {
        if(is_page('header2')) {
            include_once('inc/header/header2.php');
        } elseif(is_page('header3')) {
            include_once('inc/header/header3.php');
        } else {
            include_once('inc/header/header1.php');
        }
    }   
?>

I've managed to do, but by selecting the headers used in Theme Options and indicate any changes in the selected header.

So for the demo, I want to make that a user can see some of the views that exist in the header menu link 'Header Layout' Such, for example:

Header Layout 
|_ Header 1 Layout (Calling header1.php) 
|_ Header 2 Layout (Calling header2.php) 
|_ Header 3 Layout (Calling header3.php) 
|_ Header 4 Layout (Calling header4.php) 
|_ Header 5 Layout (Calling header5.php) 

How can I do that? and how to call any of the headers in the Appearance> Menus in WordPress?

Thank you :)

share|improve this question
2  
Saying you want to call headers in a menu is hard to understand, maybe clarify your question. –  Wyck Jun 22 at 4:24

1 Answer 1

up vote 1 down vote accepted

Use get_header($name) where $name corresponds to a file in your theme with the following convention:

header-{name}.php

So the following calls correspond to theme files in this manner:

get_header('style1') //header-style1.php
get_header('style2') //header-style2.php
get_header('style3') //header-style3.php

Example:

<?php

    if($options['header_style']) {

        if(is_page('header2')) {

            get_header( 'style2' );

        } elseif(is_page('header3')) {

            get_header( 'style3' );

        } else {
            //dynamically generating the name
            get_header( 'style' .  $options['header_style'] );

        }

    }  

    //etc...
?>

Of course the $name can be anything you want.

See http://codex.wordpress.org/Function_Reference/get_header for more details.

As for your menu, you can link to the corresponding page that displays the desired header or you could in fact get more complex than that and have the menu items correspond to rewrite rules and query vars that then invoke different header templates.

But let's see if the above helps you any before we go deeper.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.