index.php is not loaded for single posts

Your question and answer comes down to template hierarchy and how it works, and it is really really useful to know the basics here.

I’m not going to go into details as I will need to write a short story, but here are the basics:

  • WordPress uses a very strict hierarchy for loading templates on a specific page request. This hierarchy is known as the template hierarchy which you will have to work through at your own pace. This hierarchy remains constant and never change, except if the core developers changes it in newer versions (like the introduction of some new extra templates in versions 4.3 and 4.4), or if it is changes via one of the template filters.

  • WordPress is coded in such a way that the only template you will ever need to display any page on is index.php. This template is the ultimate fallback template for any page request and is the template lowest in any given hierarchy. This will in all probability never change.

  • The template highest in the hierarchy will be loaded first, if found, otherwise, the first available template lower down in the hierarchy will be loaded. As it goes, if no special template is found, WordPress will always load index.php. Any other custom template can however be used in stead of these through the specific template filters provided

  • Any other template in a specific hierarchy, except index.php (which is a must-have template), is the nice-to-have templates. They are only there for convenience and their usage are optional. These template only serves to create a specific look and feel on the front end of the site for a specific page request through special functions or CSS and/or JS effects.

To put everything in perspective, lets look at your specific case. Lets look at the template hierarchy for single posts

The single post template file is used to render a single post.
WordPress uses the following path:

  1. single-{post-type}-{slug}.php – (Since 4.4) First, WordPress looks for
    a template for the specific post. For example, if post type is product
    and the post slug is dmc-12, WordPress would look for
    single-product-dmc-12.php.

  2. single-{post-type}.php – If the post type
    is product, WordPress would look for single-product.php.

  3. single.php
    WordPress then falls back to single.php.

  4. singular.php – Then it falls
    back to singular.php.

  5. index.php – Finally, as mentioned above,
    WordPress ultimately falls back to index.php.

As you can see, in the above hierarchy, single.php is a higher ranking template than index.php, and since single.php exist in your theme, WordPress will always load single.php, and never index.php (or even singular.php) for a single post page (except if this behavior is interfered with through the single_template filter).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)