Five Events In The Life Of Every WordPress
Request You Should Know
Josh Pollock
How Do We Get From This?
You're About To Get Super Powers
Let's Talk About Hooks
A hook is an event
Actions
Do Something At This Point
do_action( 'something' );
add_action( 'something', function() {echo 'Doing Something';
});
Filters
Change Something At This Point
$something = apply_filters( 'something', 'something' );add_filter( 'something', function( $something) {
$something = 'something else';return $something
});
You've Seen This Before
add_filter( 'the_content', function( $content ) {$content .= '<a href="#">Share</a>';return $content;
}add_action( 'wp_head', function() {
echo "<script>alert( KHAAAAAAN!' ); </script>";}
What Does WordPress Do?
Five Events You Should Know
init
/wp-includes/class-wp.php
Fires When WordPress Is Loaded
/wp-includes/class-wp.php
Before:● muplugins_loaded● plugins_loaded● setup_theme● after_setup_themeAfter:● wp_loaded
Related Actions
request
/wp-includes/class-wp.php
Modifies Query Vars Before Building WP_Query
/wp-includes/class-wp.php
Actions:● parse_request● send_headersFilters:● query_string● wp_headers
Related Hooks
pre_get_posts
/wp-includes/query.php
Modifies WP_Query Arguments Before Querying
/wp-includes/query.php
Actions:● start_loop● end_loopFilters:● the_posts● the_post
Related Hooks
template_redirect
/wp-includes/template.php
Before Choosing A Template
/wp-includes/template.php
Do something instead of the template hierarchy.
WHY?
THEN THE TEMPLATE HIERARCHY HAPPENS
template_includes
/wp-includes/template.php
Change the template selected by the template hierarchy
WHY?
CalderaWP.comIngotHQ.com@Josh412
JoshPress.net