What does index php do in wordpress?

The WordPress index.php is a PHP file. It acts as a standard theme file to display a home page on websites and applications. Moreover, every page on a website delivers an index.php file with different customization from the database.

For instance, if you are accessing website.com, you are most probably accessing website.com/index.php.

index.php is a “catch-all” template — it is a fallback template when no appropriate template is found within the template hierarchy.

The template hierarchy above illustrates that if WordPress cannot find a specific template file, it skips right down to index.php as the theme’s standard homepage template file.

Therefore, index.php is the code used to provide the most generic template in a theme. It acts as a front controller ensuring every page of a site is displayed appropriately.

For example,  if someone visits your blog address in //website.com/blog/category/mountains/,WordPress will look to render the template file of the current page, which is category-mountains.php.

However, if the specific template file is missing, WordPress will look for a generic category template file like category.php.

If that file is also missing, WordPress will fall back to the main theme template file that is index.php.

Because of that, the index.php code should be as basic as it can get, as it needs to be reliable for every new page loaded. 

Here is what a default wordpress index.php code looks like:

Chủ Đề