When somebody requests a page from a WordPress website, the software performs lots of actions before rendering the page in the browser.
Have you ever wondered what WordPress does during that time?
According to this infographic created by WPBeginner, WordPress performs no less than 29 actions from the initial request to producing a fully-loaded web page which visitors can read and interact with.
In case the writing in the infographic is too hard for you to read on your device, scroll down for the ‘on-page’ version.
1. Load wp-config.php file
The wp-config.php file is the WordPress configuration file. It sets global variables for a WordPress site and contains your database information.
2. Setup default constants
This includes information like default WordPress upload location, maximum file sizes and other defaults constants set in the wp-config.php.
3. Load advanced-cache.php file
If advanced-cache.php file exists on your site, WordPress will load it. You will see a new item on the plugins screen called Drop-ins.
4. Load wp-content/db.php file
Developers can create database abstraction layers and load them in a db.php file inside the wp-content folder. If this file is present, then WordPress will load it.
5. Connect MySQL and select database
WordPress will now connect to the MySQL server and select the database. If WordPress is unable to connect to the database, you will see “Error establishing database connection”.
6. Load object-cache.php or wp-inlcudes/cache.php file
WordPress will now look for the object-cache.php file. If it doesn’t exist, WordPress will move on to load the wp-includes/cache.php file.
7. Load wp-content/sunrise.php file
If it is a multisite network, then WordPress will now load the sunrise.php file if it exists in the wp-content folder.
8. Load localization library
WordPress will now load the l10n.php library in the wp-includes folder. This file loads the WordPress localization system, loads translations, set locales etc.
9. Load multisite plugins
If it is a multisite network, WordPress will now load the multisite plugins.
10. Do action ‘muplugins_loaded’
The action muplugins_loaded is now run by WordPress. This action is available only to network activated plugins on a WordPress multisite.
11. Load active plugins
WordPress will now load all active plugins by looking the in active_plugins entry in the options table of your database. This way, WordPress will ignore inactive plugins.
12. Load pluggable.php file
The pluggable.php file contains functions that can be redefined by WordPress plugins. WordPress sees if the functions inside this file are already defined by another plugin. Otherwise, it will define those functions itself.
13. Do action ‘plugins_loaded’
WordPress will now run the action ‘plugins_loaded’. It allows developers to hook their functions to run after all the active plugins have been loaded.
14. Load rewrite rules
WordPress will now load the rewrite rules. These rules help WordPress use SEO friendly URLs.
15. Initiate $wp_query, $wp_rewrite, $wp
At this point WordPress loads the following objects:
$wp_query: The global instance the holds your WP_Query class. It tells WordPress what content is requested in a typical WordPress query format.
$wp_rewrite: The global instance that holds your WP_Rewrite class. It contains your rewrite rules and functions which tell WordPress which URL to use to display the requested content.
$wp: The global instance of the WP class which contains the functions that will parse your request and perform the main query.
16. Do action ‘setup_theme’.
WordPress will now move on to run the ‘setup_theme’ action. This action runs before your WordPress theme is loaded.
17. Load child theme’s functions.php file
The functions.php file is used in WordPress themes add theme specific features. If you are using a child theme, WordPress loads your child theme’s functions.php. Otherwise, it loads your current active theme’s functions.php file.
18. Load parent theme’s functions.php file
If you are using a child theme, WordPress now loads your parent theme’s functions.php file.
19. Do action ‘after_setup_theme’
This action runs after WordPress has setup the theme and loaded theme functions. It is the first action available to themes.
20. Setup current user object
At this point, WordPress loads the current user object. It allows WordPress to manage the request in accordance with the user’s role and capabilities.
21. Do action ‘init’
WordPress has so far loaded all the crucial information it needs. Now it fires the ‘init’ action.
This action allows developers to add code that needs to be executed after WordPress has loaded all previously mentioned information.
22. Do action ‘widget_init’
The widget_init action allows developers to register widgets and run code they needed to run at this time.
23. Run WP()
WordPress now calls wp() function which is located in the wp-inlcudes/functions.php file. It sets up the WordPress query gloabls $wp, $wp_query, $wp_the_query and then calls $wp->main.
24. Parse request
Now WordPress has all the information to parse the user request. It starts by checking the rewrite rules to match the user’s request. Then runs query variable filters, request action hook and sends header request.
25. Run query
If no content matches the query, then WordPress will set is_404 variable.
Otherwise, WordPress will go on to load query variables.
It will then run WP_Query->get_posts().
Next, it fires DO_ACTION_REF_ARRAY ‘pre_get_posts’ action with WP_Query object.
WordPress will now run apply_filters to clean up query and run some final checks.
Now it fetches posts from the database and applies posts_results and the_posts filters.
The query part ends with WordPress returning the posts.
26. Do action ‘template_redirect’
WordPress will now run the template_redirect action. This hook runs just before WordPress determines which template page to load.
27. Load feed template
If the requested content is an RSS feed, the WordPress loads the feed template.
28. Load template
WordPress will now look for the template file based on the WordPress template hierarchy. It then loads the template which usually contains a WordPress loop.
29. Do action ‘shutdown’
Just before ending all PHP execution, WordPress fires the last action called shutdown.
WordPress stops working here. It has run the code and generated user’s requested web page.
That’s a lot of stuff happening, all within a few milliseconds.
If you’re on shared web hosting and suffering from slow-loading pages, this might give you an insight into some of the reasons why your pages take a long time to load. Moving to a hosting company with more powerful servers will definitely help loading times as their equipment process all these requests in a shorter time.