Custom Theme Building & Permalinks

The Action Reference may give you some insight into what’s going on when you visit a front-end page in WordPress and help you to understand things a bit better.

Actions are events that occur in the process of loading a page, they let you “hook” into the process to run your own code at specific times. The section Actions Run During a Typical Request shows these events roughly in the order they happen, so we can follow along and figure out what’s going on. Most of the action names are pretty self-explanatory, we’ll skip ahead through the list to the wp_loaded action.

Up to this point we’ve loaded some things and established the initial state, after this is where the query action happens- “The Automagic”. The requested URL is parsed to determine what has been requested, and is converted to query variables for the “Main Query”, which runs between the posts_selection and wp actions. This is where the data is loaded that “The Loop” will ultimately operate on, and the results of this query determine how all the is_ Conditional Tags are set up, and what template file gets loaded according to the Template Hierarchy.

After the query runs, we see template_redirect, which is the last action before your template is loaded.