WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Changing header.php files? (7 posts)

  1. anonymical7
    Member
    Posted 1 year ago #

    Hi guys,

    I have found bits and pieces of things online but not anything extensive for the newbie.

    If I have made header files such as:
    headercontact.php
    headerwork.php

    How can I get them to show up on the pages that display that header?

    I found this and modified it online, but each time I try to add it to my functions.php file, I get syntax errors.

    if (is_page(‘contact’)){
(TEMPLATEPATH.’/headercontact.php’);
}
elseif (is_page(‘gallery’)){
(TEMPLATEPATH.’/headerwork.php’);
}
else {
(TEMPLATEPATH.’/header.php’);

    If theres a plugin that could conceivably rotate header.php files that would be cool, but I cant seem to find this and figure I need to learn this.

    Thanks! A

  2. Pioneer Valley Web Design
    Member
    Posted 1 year ago #

    It may be easier to create new page templates and use your code from the files you noted above to replace get_header in new page templates (then assign new templates to pages desired).

  3. Peter_L
    Member
    Posted 1 year ago #

    Solution is quite simple.

    Step 1: rename your header files to
    header-contact.php
    header-work.php
    ...

    Step 2:
    In your template files, f.e. index.php or page.php or single.php:
    instead of calling get_header(),
    you call
    get_header('contact'); or
    get_header('work');

    get_header() will call the header.php file.

  4. anonymical7
    Member
    Posted 1 year ago #

    Ah! Thanks! Im going to try it! A
    Really appreciate the fast response!

    If anyone else has feedback, im open to all!

  5. anonymical7
    Member
    Posted 1 year ago #

    It worked! But I seem to have lost my editing bar when logged in on those pages.
    You know, the grey one at the top from the wp-admin... but it worked! Thanks!

  6. Peter_L
    Member
    Posted 1 year ago #

    make sure you have wp_head() included in the new header-XXX.php files.

  7. anonymical7
    Member
    Posted 1 year ago #

    Ah, yes, actually it was the <?php do_action('wp_footer'); ?>
    that was missing. My mistake.

    Thanks all!

Topic Closed

This topic has been closed to new replies.

About this Topic