• This normally isn’t a problem since I can use is_home() to make index.php display the correct content, but I try my best to adhere to standards, so I created a home.php template to follow the Template Hierarchy.

    The site is using WordPress as its CMS, not just a blogging tool, so the instance is installed to the root of the host; the URL https://www.mysitename.com/ will send you directly to the WordPress instance.

    What happens in my case is that index.php is being called before home.php; is home.php only called first if the WordPress instance is installed to a sub-directory (https://www.mysitename.com/wp/)?

    I do not have a static page set for the site.

    This isn’t going to stop development, but I would like to adhere to the Template Hierarchy to future-proof the site against changes to the template structure.

    Any advice would be helpful, so thank you in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Sounds like you are on the right track.

    In your WordPress root, index.php will always get loaded first. It’s a web server configuration and that’s the normal behavior.

    The home.php is for your theme directory. When you create the home.php file there, it takes care of the is_home() for you.

    See this list for more information.

    https://codex.www.ads-software.com/Theme_Development#Template_Files_List

    See the rest of that article for additional theme info.

    Thread Starter leejk_sun

    (@leejk_sun)

    Thanks for the reply!

    I understand that the server will look for index.php first, but as I understand how WordPress works, the server will find index.php in the root of the instance (which defines() the theme and calls wp-blog-header.php), then draws out all the theme templates from the theme folder.

    Inside that theme folder I have an index.php file (as required) and a home.php file. If I am understanding the template hierarchy correctly, when the index.php file in the root of the instance calls the templates in the theme folder, it should load up what I have in home.php instead of index.php.

    Thread Starter leejk_sun

    (@leejk_sun)

    This question really stems from this paragraph (from https://codex.www.ads-software.com/Template_Hierarchy#Examples):

    “If a visitor goes to your home page at https://example.com/wp/, WordPress first determines whether it has a static front page. If a static front page has been set, then WordPress loads that page according to the page template hierarchy. If a static front page has not been set, then WordPress looks for a template file called home.php and uses it to generate the requested page. If home.php is missing, WordPress looks for a file called index.php in the active theme’s directory, and uses that template to generate the page.”

    When they cite this url: “https://example.com/wp/” it makes me inclined to believe that the Template Hierarchy in this case (but hopefully not others) will only work in sub-directory installations of WordPress.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Index.php is loading before Home.php’ is closed to new replies.