• I’ve noticed something a little confusing about the way my site loads pages.

    If i have a page that is a “category view”, for example if I set my hompage to be my latest posts, the browser window loads index.php (according to devtools).

    If I load a “page”, that is set to the default template, it loads page.php.

    However, if I set a page to a template other than default, the browser doesn’t load the template.php as I might have expected, it actually loads header.php – at least that’s what shows in the html in devtools, even though the template content does show in the browser below the header.

    Normally, I wouldn’t worry about this as everything “looks” ok. However, I have custom js script which is in my header.php, but is addressing a css class in the content below the header, whether it is page.php, index.php or anything else – and it doesn’t work on template pages other than the default template.

    Is this sort of thing “normal” for WP, or is it a specific issue with my theme i wonder?

Viewing 2 replies - 1 through 2 (of 2 total)
  • @dsb01 Sounds like a specific issue related to your theme. There are many ways that a theme designer can choose to create template pages and from what you have described it sounds like they have included the page templates in the functions.php which is a bit unusual but I have seen it on a few themes. Do you see template.php files in your theme root directory or a sub-directory? If they are not in the root directory, then I would assume they are added via the functions.php but they should still be affected by custom js in the header.php unless the header.php is bypassed by calling the template (again that would be unusual but not unheard of).

    I would suggest reaching out to the developer of your theme for further details on how to customize the templates. It is possible that your theme has online documentation that will provide you with all the answers you need related to the theme.

    Thread Starter dsb01

    (@dsb01)

    Thank you for your reply! Was just about to post back when I saw it…

    Yes, it is related to the theme, but not the fault of the developer, it’s a result of my own customizations which I had overlooked!

    I had the idea to “wrap” my entire WP site with a changing background, depending on which pages are visited. It’s probably rather unconventional (or at least I’ve done it in an unconventional way)… in order to do this, I added html and head tags to my theme’s index.php and page.php files, so that I could then add “site-content” and “site-wrapper” divs BEFORE the <?php get_header(); ?> function, thus wrapping the entire site.

    I can only assume I must have tried just adding the divs and it didn’t work… my memory fails me..
    I’ve obviously pasted the head info from somewhere as I seem to also have <?php wp-head()?> within my <head> section – without being entirely sure what it’s doing there!

    Anyway, having added a head section to the template php in question it now works as I hoped.

    Apologies for being a self-confessed tinkerer, but maybe the info here will be of some help to someone down the line ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘template pages vs default page.php / index.php’ is closed to new replies.