Theme document structure
-
[ Moderator note: moved to How-to and Troubleshooting. ]
Hi!
I love theming with WordPress. However, I have a question/request about template document structure…
It is usual to find open tags in header.php which are subsequently closed in footer.php. I’m not keen on this. I like each template file to have their closing tags included too. For example, this is the code from my current theme’s index.php:
<!doctype html> <html> <head> <?php get_template_part('head'); ?> <?php wp_head(); ?> </head> <body> <div class="top"> <!-- necessary to produce the sticky footer --> <?php get_header(); ?> <?php get_template_part('feature'); ?> <?php get_template_part('content'); ?> </div> <!-- .top --> <div class="bottom"> <!-- wrapper for the sticky footer --> <?php get_footer(); ?> </div> <!-- .fullwidth bottom --> <?php wp_footer(); ?> </body> </html>I realise that the usual approach involves slightly fewer template files compared to this. However, I’d argue that this approach makes for a much more readable / user friendly document structure. The outline of the page is complete, and each template file is a discrete section of code.
You may be wondering why I didn’t put wp_head() in head.php… I did it because, from my approach, wp_footer() can’t get into footer.php. I like parity. (Both header.php and footer.php only include page content that is used on every page).
I’d like to know how the current practice evolved, and whether anyone else has my OCD compulsion to close tags in template files.
The topic ‘Theme document structure’ is closed to new replies.