Have you ever interested in how WordPress actually works behind the scenes?

For a typical user, it seems simple because your A URL and a page-load in few seconds, but there are tons that happen behind the scenes.

In this guide, we’ll walk you thru how WordPress actually works behind the scenes, and that we have created a simple to follow infographic also.

What is WordPress?

WordPress may be a website builder and content management system. it’s open-source software that anyone can use to form any quiet website imaginable. It began as a blogging platform in 2003 but soon transformed into a CMS and later a full-fledged website building platform. Today it powers quite 38% of all websites on the web. To learn more about its evolution, history, and pros & cons, see our comprehensive guide on what’s WordPress?, and the way much it costs to create a WordPress site. Why you ought to find out how WordPress Works? WordPress is open-source software, which suggests anybody can study its code and write their own apps (plugins) and templates (themes) for it. Learning how WordPress works and what goes on behind the scenes can assist you to understand what you’ll do with it. you’ll study improving WordPress performance and write better code for your own projects. This guide will walk you thru the entire process step by step. we’ll start from when a user requests a page and end when that page is fully loaded.

Ready? Let’s start.

You can also follow our written tutorial below for more details.

1. Load wp-config.php File

The wp-config.php is that the WordPress configuration file. It sets global variables for a WordPress site and contains your WordPress database information. this is often the primary file WordPress loads for obvious reasons. Learn more about the wp-config.php file and the way to edit it.

2. Setup Default Constants

After loading the wp-config.php file, WordPress will advance to line default constants. This includes information like default WordPress upload location, maximum file sizes, and other default constants set in the wp-config.php file.

3. Load advanced-cache.php File

If the advanced-cache.php file exists on your site, then WordPress will load it next. This file acts as a drop-in file and is employed by several popular plugins particularly WordPress caching plugins. If your site is using this file, then you’ll see a replacement item on the plugins screen called Drop-ins.

4. Load wp-content/db.php File

WordPress allows developers to make their own database abstraction layers and cargo them during a db.php file placed inside the wp-content folder. it’s commonly employed by WordPress caching plugins to enhance database performance. If your website has this file present, then WordPress will load it.

5. Connect MySQL and choose Database

WordPress now has enough information to proceed further. it’ll advance to attach to the MySQL server and choose the database.

If WordPress is unable to attach to the database, then you’ll see the “Error establishing database connection” error and WordPress will quit right here.

If everything works fine, then it’ll advance to the next steps.

6. Load object-cache.php or wp-includes/cache.php File

WordPress will now search for the object-cache.php file. If it doesn’t exist, then WordPress will advance to load the wp-includes/cache.php file.

7. Load wp-content/sunrise.php File

If it’s a multisite network, then WordPress will now search for the sunrise.php file if it exists within the wp-content folder.

8. Load Localization Library

WordPress will now load the l10n.php library within the wp-includes folder. This file loads the WordPress localization system, loads translations, set locales, etc. See our guide on the way to use WordPress in other languages.

9. Load Multisite Plugins

If it’s a multisite network, then WordPress will now load the multisite plugins. Learn more about how plugins work on WordPress multisite network.

Wordpress

10. Do Action ‘muplugins_loaded’

The action muplugins_loaded is now traveled by WordPress. This action is out there only to network activated plugins on a WordPress multisite.

11. Load Active Plugins

WordPress will now load all active plugins on the location. It does that by looking within the active_plugins entry within the options table of your WordPress database. this enables WordPress to ignore plugins that are installed on your site but not activated.

12. Load pluggable.php File

The pluggable.php file contains functions that will be redefined by WordPress plugins. WordPress will now see if the functions inside this file are already defined by another plugin. Otherwise, it’ll define those functions themselves.

13. Do Action ‘plugins_loaded’

WordPress will now run the action ‘plugins_loaded’. It allows developers to hook their functions to run in any case active plugins are loaded.

14. Load Rewrite Rules

WordPress will now load the rewrite rules. These rewrite rules help WordPress use SEO friendly URLs.

15. Instantiate $wp_query, $wp_rewrite, $wp

At now WordPress loads the subsequent objects:

$wp_query: the worldwide instance that holds WP_Query class. It tells WordPress what content is requested during a typical WordPress query format.

$wp_rewrite: the worldwide 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 worldwide instance of the WP class which contains functions that will parse your request and perform the most query.

16. Do Action ‘setup_theme’

WordPress will now advance 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 acts as a plugin and is employed in WordPress themes to feature theme-specific features to your website. If you’re employing a child theme, then WordPress will now load your child theme’s functions.php file.

Otherwise, it’ll continue and cargo your current active theme’s functions.php file.

18. Load Parent Theme’s functions.php File

If you’re employing a child theme, then WordPress will now load your parent theme’s functions.php file.

19. Do Action ‘after_setup_theme’

This action runs after WordPress has set up the theme and loaded theme functions. it’s the primary action available to themes.

20. Setup Current User Object

At now, WordPress loads the present user object. It allows WordPress to manage the request in accordance with the user’s role and capabilities.

21. Do Action ‘init’

WordPress has thus far loaded all the crucial information it needs. Now it fires the ‘init’ action.

This action allows developers to feature code that must 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 the code they needed to run at this point.

23. Run wp()

WordPress now calls wp() function which is found in wp-includes/functions.php file. It sets up the WordPress query globals $wp, $wp_query, $wp_the_query then calls $wp->main.

24. Parse Request

Now WordPress has all the knowledge it must parse the user request. It starts by checking the rewrite rules to match the user’s request.

And 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 the is_404 variable.

Otherwise, WordPress will continue 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 wash up queries 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 may be an RSS feed, then WordPress loads the feed template.

28. Load WordPress Template

WordPress will now search for the template file supported 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’s run the code and generated the user’s requested website.

Now, your web hosting server replies to user’s requests by sending them the online page generated by WordPress. This page contains HTML, CSS, and Javascript code, which tells the user’s browser the way to display it on screen.

Amazing isn’t it? of these things happen within milliseconds. If you’re using one of these best WordPress hosting services, then ideally your page will load in a few seconds.

Read More:

Database Error

Amazon Affiliate WordPress Plugin and Theme