• Resolved Bperth

    (@bperth)


    Hi All,

    I’m trying to use a different header file for page.php using the description at:

    https://codex.www.ads-software.com/Function_Reference/get_header

    I’ve created a copy of header.php name header2.php and put a small message in its body tag to test if it’s being used ie:

    <?php echo “hello hello hello hello hello hello” ?>

    I’ve changed the call in page.php from

    get_header();

    to get_header(‘header2’);

    but it doesn’t display hello (ie use the header2.php file).

    Any ideas?

    Thanks

    Bruce

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi again Bruce,
    Rename the header2 to header-2.php, get_header() splits the filename at the hyphon ‘-‘ to ‘header’ and ‘2’

    With your example it is looking for a file called header-header2.php

    if a name is specified then a specialised header header-{name}.php

    HTH

    David

    Thread Starter Bperth

    (@bperth)

    Hi again Dave,

    Thanks again for your prompt reply.
    I still don’t get it.
    I’ve renamed the file header-2.php
    I’ve tried calling it with
    get_header(header-2)
    and
    get_header(header2)
    neither seem to work.

    Bruce

    Thread Starter Bperth

    (@bperth)

    Ah!

    You only use the part of the name concatinated onto header-{name}.php
    ie
    get_header(‘name’)

    thanks

    Sorry,
    I should have given the example for other readers of this topic
    get_header(‘2’); this calls header-2.php
    get_header(‘single’); this calls header-single.php

    Both these examples, if the file does not exists then no error is generated WordPress will fall through to use header.php

    Regards

    David ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘cannot use different header file’ is closed to new replies.