What are the ADVANTAGES of ORIGINAL wordpress template structure?

First, as @Toscho implies, the get_header() and get_footer() template tags simply include files named header.php and footer.php, respectively. Both template tags are called from within template files, and you can separate content between template file (index.php) and template part file (header.php, footer.php) any way you want. So, WordPress certainly can accommodate your latter example.

That said, the real power in the standard, “WordPress” method of separating content derives from the WordPress Template Hierarchy. In WordPress, the index.php file is actually the last template file used. It is the default fallback template file when no other, more-specific template file is found:

WordPress Template Hierarchy

Since any one of 7 (primary) to 16 (secondary) template files (and that’s just for a publicly distributed Theme; custom-designed Themes can have any number of template files) will be used, depending on the current context, the “WordPress” method of markup separation minimizes the amount of duplicated code.

Let’s say you want to change your doctype from transitional to strict (or you want to move to HTML5), or that you want to change your copyright statement in your site footer. Using the “WordPress” method of markup separation, you make those changes in one file. Using your latter method of content separation, you make those changes seven to sixteen (or more) times.

Edit

I figured this question would come up:

I want to hear your opinion concerning following situation. Let’s say we need to include “og tags (Open Graph meta tags)” and they have different format for “index”, “single.php” “page” “archive” templates. If we have a structure like “original wp theme structure” then we have to use conditional statements(if..else) in the “header.php” file, right ? And I think everybody agrees less “conditional statements” better performance per request, right ?

We have several options:

  1. Use PHP query conditionals directly inside header.php
  2. Use PHP query conditionals in callbacks, hooked into wp_head (or wp_enqueue_scripts, etc.)
  3. Use get_header( $context ), where $context is based on the template hierarchy, and which will include header-$context.php if found, or header.php if not found.

But the multiple options don’t really address your underlying question regarding performance hit. Personally, I think the performance hit is negligible, because all of the query conditionals are cached as part of the query object cache, anyway. So calling them really shouldn’t incur any meaningful performance hit.

Leave a Comment