WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
    • Business Name Ideas
  • Deals
    • Bluehost Coupon
    • SiteGround Coupon
    • WP Engine Coupon
    • HostGator Coupon
    • Domain.com Coupon
    • Constant Contact
    • View All Deals »
  • Glossary
  • Videos
  • Products
X
☰
Beginner's Guide for WordPress / Start your WordPress Blog in minutes
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

WPBeginner» Blog» Tutorials» How WordPress Actually Works Behind the Scenes (Infographic)

How WordPress Actually Works Behind the Scenes (Infographic)

Last updated on September 28th, 2020 by Editorial Staff
481 Shares
Share
Tweet
Share
Pin
Free WordPress Video Tutorials on YouTube by WPBeginner
How WordPress Actually Works Behind the Scenes (Infographic)

Have you ever wondered how WordPress actually works behind the scenes?

For a typical user, it seems simple because you type a URL and a page loads in few seconds, but there is a lot that happens behind the scenes.

In this guide, we will walk you through how WordPress actually works behind the scenes, and we have created an easy to follow infographic as well.

How WordPress Works Behind the Scenes

What is WordPress?

WordPress is a website builder and content management system. It is an open source software that anyone can use to make any kind of website imaginable.

It started out as a blogging platform in 2003 but soon transformed into a CMS and later a full-fledged website building platform. Today it powers more than 38% of all websites on the internet.

To learn more about its evolution, history, and pros & cons, see our comprehensive guide on What is WordPress?, and how much it costs to build a WordPress site.

Why You Should Learn How WordPress Works?

WordPress is an open source software, which means any one 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 help you understand what you can do with it. You can learn about improving WordPress performance and write better code for your own projects.

This guide will walk you through the whole process step by step. We will start from when a user requests a page and end when that page is fully loaded.

Ready? Let’s get started.

Click to View the Behind the Scenes WordPress Infographic

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

1. Load wp-config.php File

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

2. Setup Default Constants

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

3. Load advanced-cache.php File

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

advanced-cache.php file appearing as drop-in

4. Load wp-content/db.php File

WordPress allows developers to create their own database abstraction layers and load them in a db.php file placed inside the wp-content folder. It is commonly used by WordPress caching plugins to improve database performance. If your website has this file present, then WordPress will load it.

5. Connect MySQL and Select Database

WordPress now have enough information to proceed further. It will move on to connect to the MySQL server and select the database.

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

If everything works fine, then it will move on to next steps.

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

WordPress will now look for object-cache.php file. If it doesn’t exist, then WordPress will move on to load wp-includes/cache.php file.

7. Load wp-content/sunrise.php File

If it is a multisite network, then WordPress will now look for sunrise.php file if it exists in the wp-content folder.

8. Load Localization Library

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

9. Load Multisite Plugins

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

Network activated 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 on the site. It does that by looking in the active_plugins entry in the options table of your WordPress database. This allows 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 can be redefined by WordPress plugins. WordPress will now see 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 active plugins have been 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 this point WordPress loads the following objects:

$wp_query: The global instance that holds 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 functions that will parse your request and perform the main query.

16. Do Action ‘setup_theme’

WordPress will now move on to run ‘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 plugin and is used in WordPress themes to add theme specific features to your website. If you are using a child theme, then WordPress will now load your child theme’s functions.php file.

Otherwise, it will go on and load your current active theme’s functions.php file.

18. Load Parent Theme’s functions.php File

If you are using 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 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 wp-includes/functions.php file. It sets up the WordPress query globals $wp, $wp_query, $wp_the_query and then calls $wp->main.

24. Parse Request

Now WordPress has all the information it needs to 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 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 a RSS feed, then WordPress loads the feed template.

28. Load Template

WordPress will now look for the template file based on 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.

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

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

We hope this article helped you learn how WordPress works behind the scenes. You may also want to see our step by step guide on how to boost WordPress speed and performance for beginners.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

481 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • How to Start Your Own Podcast (Step by Step)

    How to Start Your Own Podcast (Step by Step)

  • How to Fix the Error Establishing a Database Connection in WordPress

    How to Fix the Error Establishing a Database Connection in WordPress

  • How to Properly Move Your Blog from WordPress.com to WordPress.org

  • Checklist

    Checklist: 15 Things You MUST DO Before Changing WordPress Themes

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

The Ultimate WordPress Toolkit

28 Comments

Leave a Reply
  1. Mike Ross says:
    Nov 12, 2020 at 12:49 pm

    What about index.php in the root?

    I don’t get it…There are guides out there that lay out a totally different sequence of WordPress initialization.

    Reply
    • WPBeginner Support says:
      Nov 13, 2020 at 10:17 am

      Index.php would be for the theme files, we cover the theme hierarchy in our guide below:

      https://www.wpbeginner.com/wp-themes/wordpress-template-hierarchy-explained/

      Reply
    • Mike Ross says:
      Nov 13, 2020 at 10:52 am

      No, I’m not talking about the theme’s homepage template. I’m taking about the index.php at the root, which is a part of the WordPress core. It triggers wp-blog-header.php, which then loads wp-load.php which sets up the entire WordPress environment.

      Reply
      • WPBeginner Support says:
        Nov 16, 2020 at 2:22 pm

        The index.php in the root folder tells WordPress to load your theme :)

        Reply
  2. Jason says:
    Nov 1, 2020 at 4:58 pm

    Why start from wp-config.php ? I thought it was from index.php

    Reply
    • WPBeginner Support says:
      Nov 2, 2020 at 11:10 am

      That would be for themes and not WordPress itself, for the index.php you would want to take a look at the template hierarchy in our guide below:

      https://www.wpbeginner.com/wp-themes/wordpress-template-hierarchy-explained/

      Reply
  3. Petru Ciucur says:
    Oct 7, 2020 at 8:06 am

    This is THE Article. Thanks !

    Reply
    • WPBeginner Support says:
      Oct 7, 2020 at 10:12 am

      Glad our guide was helpful :)

      Reply
  4. Juan Johnson says:
    Aug 23, 2020 at 2:15 pm

    HI wpbeginner.
    I noticed that in your sequence, you mentioned that wp does this and then that. Physical, where is the instance of wp()? On the server? Does this happens in between an initial load page post request when I use google browser and the final loading of the wp dashboard after login?

    Reply
    • WPBeginner Support says:
      Aug 25, 2020 at 10:25 am

      You may want to take another look at the infographic for understanding the loading and how it works.

      Reply
  5. Juan Johnson says:
    Aug 23, 2020 at 5:33 am

    I am a programmer. I am getting more into the web page design, however, I cannot let go of wanting to know what is going on behind the scenes. You article has given me a foundation to start confidently constructing web pages.

    Reply
    • WPBeginner Support says:
      Aug 25, 2020 at 10:06 am

      Glad our guide was helpful :)

      Reply
  6. Paul McDevitt says:
    May 13, 2020 at 10:43 am

    This is brilliant. Ran into several issues with old, expired plugins, updating PHP, etc, and a virus (probably because of the prior items.) So all locked down and scrubbed up now, but wanted to understand better the sequence of events as looking into any one PHP file is like trying to read a bowl of spaghetti, as I did not understand the sequencing of the activities. So absolutely amazing. Love this.

    Thanks

    Reply
    • WPBeginner Support says:
      May 14, 2020 at 8:58 am

      Glad our article was helpful :)

      Reply
  7. Naresh says:
    Nov 4, 2019 at 8:08 am

    very clear article.

    Reply
    • WPBeginner Support says:
      Nov 4, 2019 at 10:33 am

      Thank you :)

      Reply
  8. Chinenye says:
    Jan 18, 2019 at 5:05 am

    I want to really know what wordpress does, how can I make and share posts through word press? What does it do for me apart from creating a site?

    Reply
    • WPBeginner Support says:
      Jan 18, 2019 at 10:50 am

      WordPress allows you to create a site without needing to have knowledge of HTML and CSS. For sharing your posts, you would normally want to take a look at social media plugins: https://www.wpbeginner.com/plugins/best-social-media-plugins-for-wordpress/

      Reply
  9. ganesh says:
    Apr 12, 2018 at 1:18 pm

    very interesting

    Reply
  10. Adrian says:
    Jan 23, 2018 at 6:22 pm

    Interesting but not really a definition of how WordPress works. This describes what it does, not how it does it. Would be useful to also know how it does things as well as what it does. For example how does it know which theme to load? Without the how all the above is very high level.

    Reply
  11. amir saleem says:
    Aug 26, 2017 at 3:07 am

    17. Load Child Theme’s functions.php File

    The functions.php file acts as plugin and is used in WordPress themes to add theme specific features to your website. If you are using a child theme, then WordPress will now load your child theme’s functions.php file.

    Otherwise, it will go on and load your current active theme’s functions.php file.

    18. Load Parent Theme’s functions.php File

    [ If you are using a child theme ], then WordPress will now load your parent theme’s functions.php file.

    check the text in brackets and match all the wording here will be replace [ if you are using a parent theme ].

    Thanks.

    Reply
    • Caleb says:
      Feb 7, 2020 at 9:18 am

      Amir, I think what the OP is trying to say is that if there is a child theme, then obviously there would be a parent and child functions.php and wordpress first loads the child themes functions.php before loading the parent’s. Otherwise, it just loads the parent’s functions.php straightaway.

      Reply
  12. Altab Hossen says:
    Aug 16, 2017 at 1:31 pm

    Thanks for this nice explanation and info-graphics is so cool !!

    Reply
  13. Kristian says:
    Jun 24, 2017 at 6:55 pm

    And people wonder why WordPress sites are slow. It does all that at run-time for every single page view!

    Reply
  14. Johnpaul Onwueme says:
    Jun 22, 2017 at 12:43 pm

    Thanks for the info graphics

    Reply
  15. deborah says:
    Jun 22, 2017 at 9:02 am

    still seems complicated to me, but all tech does

    Reply
  16. Jason says:
    Jun 15, 2017 at 5:58 pm

    Would you be willing to offer this as a printed poster? I don’t know if it would generate much interest or make you any money, but since it is such a nice graphic it might make a nice office wall hanging.

    Reply
  17. anis says:
    Jun 14, 2017 at 7:21 am

    Thank you for this article . I wanted to know since long time
    the different steps for loading .

    What is a database abstraction layer and how to configure it ?

    Reply

Leave a Reply Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
WPForms Logo
WPForms
Drag & Drop WordPress Form Builder Plugin. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 30 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2021 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2021)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2021)
    • SiteGround Reviews from 4464 Users & Our Experts (2021)
    • Bluehost Review from Real Users + Performance Stats (2021)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Create an Email Newsletter the RIGHT WAY (Step by Step)
    • Free Business Name Generator (A.I Powered)
    • How to Create a Free Business Email Address in 5 Minutes (Step by Step)
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2021 – Step by Step Guide
Deals & Coupons (view all)
PremiumCoding
PremiumCoding Coupon
Get 40% off on PremiumCoding's collection of beautiful WordPress themes.
Rocket coupon code
Rocket Coupon
Get 50% OFF on Rocket managed WordPress hosting plans for 3 months.
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).

Join our team: We are Hiring!

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
  • Free Business Tools
  • Growth Fund
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • RafflePress
  • Smash Balloon
  • AIOSEO

Copyright © 2009 - 2021 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

Managed by Awesome Motive | WordPress hosting by SiteGround | WordPress Security by Sucuri.