• I’m trying to create a WordPress theme but I’m facing a problem, the get_header() function doesn't inject theheader.phpcode, whileget_footer()` works fine.
    this is my code:
    header.php

    <html>
        <head>
            
            <meta charset='utf-8'>
            <meta http-equiv='X-UA-Compatible' content='IE=edge'>
            <meta name='viewport' content='width=device-width, initial-scale=1'>
            <?php
                wp_head();
            ?>
        </head>
        <body>
            <header>
                header
            </header>

    front-page.php

    <?php
    get_header();
    ?>
    front page content
    <?php
    get_footer();
    ?>

    footer.php

    <?php
            wp_footer();
            ?>
            <footer>
               footer
            </footer>
        </body>
    </html>

    The odd part is that when creating a new header-a.php file , with the exact same code as header.php I can load it using get_header('a') and it works fine;

    Any idea why it happens and how to fix it?
    Thanks.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    Is there anything odd about the file permissions?

    WebsiteGuider

    (@websiteguiderteam1618)

    Nothing seems odd.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    header.php is a php file.
    It must start with <?php

    This is incorrect.

    Thread Starter arar1

    (@arar1)

    Thanks for the replies.
    @otto42 I didn’t touch any of that, it’s a new folder folder and files

    @websiteguiderteam1618 didn’t change anything, and if I create another file header-a.php for example with the same content and use get_header('a'); it works, seems like it’s not my problem

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    I didn’t touch any of that, it’s a new folder folder and files

    Yes, but you’re creating files. So did you look at the permissions? See if there’s any difference between the header and footer perms.

    If PHP can’t read the file or see that it exists, then it’s not going to load it. That could explain why one works and the other doesn’t.

    Thread Starter arar1

    (@arar1)

    @otto42 how do I check the permissions? (they have the same perms in file explorer-> file-> properties-> security-> perms)

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    … Is this all on your computer? Do you use a Windows Server?

    The permissions of the file on the hosting system are what matter. Not on your local machine, on the host.

    This article might help you understand:

    Changing File Permissions

    Thread Starter arar1

    (@arar1)

    @otto42 I’m using localwp with nginx

    • This reply was modified 1 year, 11 months ago by arar1.
    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    I’ve never used localwp, so I can’t give you any advice on how to do it. I suggest consulting their documentation and figuring out how to adjust file permissions. Or at least how to find them in the 1st place.

    Hi @arar1

    There could be a few reasons why the get_header() function is not working as expected in your theme. Here are a few things you can try to troubleshoot the issue:

    1. Ensure that the header.php file is in your theme’s root directory. The get_header() function looks for a file with this name in the theme’s root directory, so if the file is not in the right location, it will not be loaded.

    2. Check for any PHP errors or warnings in the header.php file that could prevent it from being loaded. You can enable error reporting in WordPress by adding the following line of code to your wp-config.php file:

    define( 'WP_DEBUG', true );

    3. Check that the front-page.php template file is being used as your site’s front page. If your site uses a static front page, the front-page.php template will not be used, and the header.php file will not be included.

    I hope these suggestions help you troubleshoot the issue with the get_header() function. If you’re still having trouble, please provide more information about your theme and any error messages you may be seeing, and I’ll do my best to help.

    Thread Starter arar1

    (@arar1)

    @otto42 migrated everything to xampp + filezilla and them both have the same perms (777) and still doesn’t work. + it’s no the perms, I have added an error in header.php and WordPress recognized it

    • This reply was modified 1 year, 11 months ago by arar1.
    • This reply was modified 1 year, 11 months ago by arar1.
    • This reply was modified 1 year, 11 months ago by arar1.
Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘get_header() doesn’t work, but get_footer() does’ is closed to new replies.