How WordPress Plugins Work

Forrest Pykes Apr 15, 2025

It can be very interesting to understand how WordPress works behind the scenes. For most users, it seems simple: enter a URL and the page loads quickly. However, in reality, there is a lot more going on in the background.

When we first started working with WordPress a few years ago, we did an in-depth study of how it works. Now, we want to share this knowledge with you in layman’s terms so you can understand WordPress better.

In this guide, we’ll walk you through the inner workings of WordPress. We’ve also created an easy-to-understand infographic to give you a clearer understanding of the inner workings of WordPress.

What is WordPress?

WordPress is a website builder and content management system. It is open source software that anyone can use to create any type of website.

It originally started as a blogging platform in 2003, but quickly transitioned to a content management system (CMS), and later developed into a full-featured website building platform. Today, it powers more than 43% of the websites on the Internet.

To learn more about its evolution, history, and pros and cons, see our comprehensive guide on What is WordPress and How Much Does it Cost to Build a WordPress Website

Why should you know how WordPress works?

WordPress is open source software, which means that anyone can study its code and write applications (plugins) and templates (themes) for it.

Over the years, we’ve seen countless beginners quickly become advanced users by simply learning how the WordPress software works.

It will also teach you how to improve WordPress performance and write better code for your projects.

This guide will walk you through the entire process step by step. We will start with the user requesting the page and end with the page fully loaded.

Are you ready? Let’s get started.

You can also follow the tutorial we wrote below for more details.

1. Load the wp-config.php file

wp-config.php is the configuration file for WordPress. It sets global variables for the WordPress site and contains WordPress database information. As you can probably tell, this is the first file that WordPress loads.

2. Set default constants

Once the wp-config.php file is loaded, WordPress will proceed to set the default constants.

This includes information such as the default WordPress upload location, maximum file size, and other default constants set in the wp-config.php file.

3. Load the advanced-cache.php file

If advanced-cache.php file exists on your website, WordPress will load it next.

This file acts as a plugin file and is used by many popular plugins, especially the WordPress Cache plugin . If your website uses this file, you will see a new item called "Plugins" on the "Plugins" screen.

How WordPress Plugins Work

4. Load the wp-content/db.php file

WordPress allows developers to create their own database abstraction layer and load it into the db.php file inside the wp-content folder. This is commonly used by WordPress caching plugins to improve database performance.

If your website has this file, WordPress will load it.

5. Connect to MySQL and select the database

WordPress now has enough information to proceed to the next step. It will connect to the MySQL server and select the database.

If WordPress cannot connect to the database, you will see an "Error establishing database connection" error and WordPress will exit at this point.

If everything goes well, then it will proceed to the next step.

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

WordPress will now look for the object-cache.php file. If it does not exist, WordPress will proceed to load the wp-includes/cache.php file.

7. Load the wp-content/sunrise.php file

In case of a multisite network, WordPress will look for the sunshine.php file in the wp-content folder if it exists.

8. Load the localization library

WordPress will now load the l10n.php library from the wp-includes folder. This file is used to load the WordPress localization system, load translations, set the locale, etc.

9. Load the Multisite plugin

If it is a multisite network, WordPress will load the multisite plugin.

How WordPress Plugins Work

10. Execute the "muplugins_loaded" operation

The muplugins_loaded action is now run by WordPress. This action only works for network-activated plugins on WordPress multisites.

11. Load active plugins

WordPress will now load all active plugins on the site. It does this by looking for an active_plugins entry in the WordPress database options table. This allows WordPress to ignore plugins that are installed but not activated on the site.

12. Load the pluggable.php file

The pluggable.php file contains functions that can be redefined by WordPress plugins.

WordPress will now check if another plugin has defined the functions in this file. Otherwise, it will define those functions itself.

13. Execute the "plugins_loaded" action

WordPress will now run the action "plugins_loaded".

It allows developers to hook their functions to run after all active plugins are loaded.

14. Loading 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: Holds the global instance of the WP_Query class. It tells WordPress what to request in the typical WordPress query format.

$wp_rewrite: holds the global instance of the WP_Rewrite class. It contains rewrite rules and functions that tell WordPress which URL to use to display the requested content.

$wp: The global instance of the WP class contains the functions that will parse your request and perform the main queries.

16. Execute the "setup_theme" operation

WordPress will now proceed to run the 'setup_theme' action. This action runs before a WordPress theme is loaded.

17. Load your child theme’s functions.php file

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

Otherwise, it will continue to load your currently active theme's functions.php file.

18. Load the 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. Execute the "after_setup_theme" action

This action runs after WordPress sets up your theme and loads the theme's functions. It is the first action available to your theme.

20. Set the current user object

At this point, WordPress loads the current user object. This allows WordPress to manage the request based on the user's roles and permissions.

21. Execute the "init" operation

By now, WordPress has loaded all the critical information it needs. Now, it will trigger the “init” action. This action also registers the blocks available in the core or provided by any plugin installed on the website.

This action enables developers to add code that needs to be executed after WordPress has loaded all of the previously mentioned information.

22. Execute the "widget_init" operation

This widget_initaction allows the developer to register the widget and run the code they need to run at this time.

23. Run wp()

WordPress now calls the function wp()located wp-includes/functions.phpin the file. It sets up the WordPress query global variables wp, wp_query, wp_the_query, and then calls wp->main.

24. Parsing Request

Now that WordPress has all the information it needs to parse the user's request, it first checks to see if the rewrite rules match the user's request.

It then runs the query variable filter, requests the action hook, and sends the header request.

25. Run a query

If no content matches the query, then WordPress will set the is_404 variable.

Otherwise, WordPress will continue loading query variables.

It will then run WP_Query->get_posts().

Next, it triggers the DO_ACTION_REF_ARRAY "pre_get_posts" action using the WP_Query object.

WordPress will now run apply_filters to clean up the query and run some final checks.

Now, it fetches the posts from the database and applies the posts_results and the_posts filters.

The query portion ends with WordPress returning the posts.

26. Execute the "template_redirect" action

WordPress will now run the template_redirectaction. This hook runs before WordPress determines which template page to load.

27. Loading Feed Template

If the requested content is an RSS feed, then WordPress loads the feed template.

28. Loading Templates

WordPress will now look for the template file according to the WordPress template hierarchy. It will then load the template, which will usually contain a WordPress loop.

29. Perform the "Shutdown" operation

Before ending all PHP execution, WordPress triggers one final action called shutdown.

WordPress has stopped working at this point. It has run the code and generated the web page the user requested.

Now, your web hosting server responds to the user’s request by sending them the web page generated by WordPress.

The page contains HTML, CSS, and Javascript code that tells the user's browser how to display it on the screen.

Pretty amazing, isn’t it? All of this happens in milliseconds. If you use one of these best WordPress hosting services, your pages will ideally load in seconds.

We hope this article helped you understand how WordPress works behind the scenes.

If you liked this article, you can also share it on Twitter and Facebook.

Disclosure: Some of the links in this article contain affiliate links, which means we may earn a commission if you click through to visit us, at no extra cost to you. See how SidelinePlay is funded, why it’s important, and how you can support us.

Was this helpful?

0/400

Get free tips and resources right in your inbox, along with 60,000+ others