A look into WordPress’ index.php file, the PHP code file that starts off everything.
WordPress’ index.php is a very short code file. All it contains is two lines of code – very important one’s at that. Lets take a look at each to get a sense of what is under the hood.
WP_USE_THEMES: Turn On/Off Theming
The first line, defines a constant, WP_USE_THEMES and is set to true.
All requests to a WordPress website is sent through to index.php, the main gateway page. This is forced as WordPress relies upon mod_rewrite to exist. WordPress comes with a .htacesss Apache file that has mod_rewrite rules to send every URL request to index.php.
When index.php is executed, the WP_USE_THEMES constant is set to “true”. This tells the WordPress template loader (template-loader.php) to load the appropriate type of template based on the URL signature. If you turn WP_USE_THEMES off, no theme template file will be used and a blank page will come up (don’t believe me? Try it).
Looking through the entire WordPress source code, standard behavior is to have this on. In fact, there is no place in WordPress core where this is set to “false”.
What you can do is modify this constant in the configuration file, wp-config.php. That turns themes off. It is useful if you are using WordPress on the back end as an administrator. It effectively turns WordPress off on the front end so no visitors can see the website. You use this if you are working on the website trying to fix things.
You can also use WordPress for its framework rather than having to reinvent the wheel. For example, you can leverage its user classes and ability to store posts and pages without rendering them to people who visit the site.
Load WordPress Environment
The second line does some loading.
require( dirname( __FILE__ ) . '/wp-blog-header.php' );
This statement loads all of WordPress. I won’t go into the details of wp-blog-header.php and save that for another day. But basically, index.php includes the WordPress environment with this statement.