Support » Fixing WordPress » Why are wordpress theme templates divided?

  • I am just wondering, why WordPress developers decided to divide a layout template into a separate header.php and footer.php? What are the advantages of this solution? Isn’t it unpractical, if both of the layout code halves are in separate files, so the whole structure is divided? Why not create one layout file, which would include a main content (index.php, page.php etc.) inside itself? Is there any way how to create a theme template without the header/footer separation?

    • This topic was modified 3 years, 10 months ago by rzelnik.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The header and footer are typically the same on all templates. If the header and footer were included in index.php and page.php then any time you wanted to change the header you’d need to edit all your templates.

    That being said, you’re not required to use header.php and footer.php, so you could always just create page.php, for example, without including them.

    Thread Starter rzelnik

    (@rzelnik)

    Yes, I understand that they are the same on all templates. I do not suggest to copy the header and footer content on all templates. I suggest to create one undivided layout template, like this:

    layout.php

    <html>
      <head>
      ...
      </head>
      <body>
        ...
        <?php get_header(); ?>
        ...
        <?php get_main_content(); ?>
        ...
        <?php get_sidebar(); ?>
        <?php get_footer(); ?>
        ...
      </body>
    </html>

    This structure would be more consistend, since it’s all in one code.

    • This reply was modified 3 years, 10 months ago by rzelnik. Reason: fixed code
    • This reply was modified 3 years, 10 months ago by rzelnik. Reason: fixed code
    Thread Starter rzelnik

    (@rzelnik)

    In this case, the header.php content would be:

    <header ...>
      ...
    </header>

    and footer.php:

    <footer ...>
      ...
    </footer>
    Moderator Steve Stern (sterndata)

    (@sterndata)

    Forum Moderator & Support Team Rep

    There’s nothing to say that you couldn’t write your own theme(s) that way.

    https://developer.wordpress.org/themes/

    But all that stuff that you have before <body> would need to be in each layout, and a lot of it is generated dynamically.
    For that matter, why have more than index.php, when it could all be done in one file?
    Mostly, it’s for ease of child theming and separating it allows better understanding for the person changing things.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Why are wordpress theme templates divided?’ is closed to new replies.