Skip to main content Skip to course navigation

How WordPress actually loads

When you type a URL and hit enter, your browser sends a request to the server. The server hands it to WordPress. From that moment, WordPress runs a boot sequence — a fixed, predictable order of operations — before anything on your site appears. Understanding this sequence is what separates someone who guesses where to put code from someone who knows exactly where it runs and why.

It starts with index.php in the root of your WordPress install. That file has basically one job: load wp-blog-header.php. That file does two things in order — loads WordPress itself, then figures out what to display based on the URL.

The actual loading happens inside wp-load.php, which finds and loads wp-config.php (your database credentials, constants, debug settings), and then hands off to wp-settings.php. That file is where the real sequence lives. If you open it in your editor you’ll see WordPress doing things in strict order: defining constants, loading core helper files, connecting to the database, loading must-use plugins, loading active plugins, loading the active theme, and finally firing the query and template system.

Your plugin file gets included during that “loading active plugins” step. That means any code you write at the top level of your plugin file — outside any function or hook — runs right there, at that moment in the sequence. Which is too early for almost everything useful.

This is why hooks exist. Instead of running code at include time, you register a function to run later, at a specific point in the sequence. WordPress calls your function when it reaches that point.

The three hooks that matter most right now, in firing order:

plugins_loaded fires after all active plugins are loaded. Nothing theme-related exists yet. No template, no sidebar, no widgets. The database is connected and your plugin is in memory. Good for plugin-to-plugin compatibility checks.

init fires after plugins_loaded and is the most commonly used hook in all of WordPress. By this point it is safe to register custom post types, register taxonomies, and interact with the current user session. Most plugin setup code lives here.

wp_loaded fires after the theme is loaded and after init. Everything is in memory. Safe to read options, interact with most WordPress functions, and run logic that depends on the full environment being ready.

The rule is simple: fire too early and the thing you need does not exist yet. Fire too late and you have missed the window where WordPress expected you to act. Getting this timing right is the difference between code that works and code that works sometimes, or only for some users, or only on some pages — which is exactly the kind of bug that lands in a support ticket.