Theme template files are organized in this way because of the WordPress Template Hierarchy. Since all primary template files eventually fallback to index.php
, it is certainly possible to use only the index.php
primary template file. There are advantages and disadvantages to using either method.
Generally speaking, the usefulness/efficiency of defining template files is inversely proportional to the contextual complexity of the Theme. If your Theme output does not changed based on context, as defined in the Template Hierarchy, then using only an index.php
file makes perfect sense. However, trying to implement more-and-more complex, contextually specific output becomes increasingly difficult using only query-based conditional template tags (e.g. is_single()
, is_archive()
, is_category()
, is_404()
, etc.) inside of index.php
.
However, this is a bad idea:
If you need to change the title in your
<head>
tag, why not use the power of output-buffering (ob_start()
andob_end_clean()
)to get the posts first / the page / the single post / the search results… Is there performance issues using this technique?
There is no need for output buffering. You should use one of the following methods:
- The
the_title
filter hook to changewp_title()
output contextually - Pass a contextually defined variable directly to the
wp_title()
template tag