WordPress Hooks
by
Zac Gordon
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
WordPress Hooks Zac Gordon @zgordon
Slide 2
Slide 2 text
2000+ Hooks in WordPress
Slide 3
Slide 3 text
http://hookr.io/4.1.1/#index=a
Slide 4
Slide 4 text
200+ Hooks Actually Use
Slide 5
Slide 5 text
“Anything, Anywhere, Anytime”
Slide 6
Slide 6 text
“Anything, Anywhere, Anytime”
Slide 7
Slide 7 text
“Anything, Anywhere, Anytime”
Slide 8
Slide 8 text
“Anything, Anywhere, Anytime”
Slide 9
Slide 9 text
“Anything, Anywhere, Anytime” Filters }
Slide 10
Slide 10 text
“Anything, Anywhere, Anytime” Actions }
Slide 11
Slide 11 text
Filters vs Actions
Slide 12
Slide 12 text
Filters modify something
Slide 13
Slide 13 text
Actions do something
Slide 14
Slide 14 text
Filters in Core
Slide 15
Slide 15 text
$admin_title = apply_filters( 'admin_title', $admin_title ); … wp-admin/admin-header.php
Slide 16
Slide 16 text
Actions in Core
Slide 17
Slide 17 text
… … wp-admin/admin-header.php
Slide 18
Slide 18 text
What Is Possible?
Slide 19
Slide 19 text
Read the Codex
Slide 20
Slide 20 text
http://codex.wordpress.org/Plugin_API/Filter_Reference http://codex.wordpress.org/Plugin_API/Action_Reference
Slide 21
Slide 21 text
http://codex.wordpress.org/Plugin_API/Filter_Reference Filters
Slide 22
Slide 22 text
http://codex.wordpress.org/Plugin_API/Action_Reference Actions
Slide 23
Slide 23 text
http://codex.wordpress.org/Plugin_API/Action_Reference Runtime
Slide 24
Slide 24 text
http://codex.wordpress.org/Plugin_API/Action_Reference/init Reference Pages
Slide 25
Slide 25 text
http://hookr.io http://wpseek.com
Slide 26
Slide 26 text
$wp_filter
Slide 27
Slide 27 text
"; var_export( $wp_filter ); echo “”;? ?> theme/functions.php
Slide 28
Slide 28 text
$wp_filter
Slide 29
Slide 29 text
$wp_filter http://www.rarst.net/wordpress/debug-wordpress-hooks/
Slide 30
Slide 30 text
Helpful Plugins
Slide 31
Slide 31 text
Simply Show Hooks https://wordpress.org/plugins/simply-show-hooks/
Slide 32
Slide 32 text
WP Query https://wordpress.org/plugins/query-monitor/
Slide 33
Slide 33 text
Back to the Code
Slide 34
Slide 34 text
Power of Search
Slide 35
Slide 35 text
SublimeText Ctrl + Shift + F
Slide 36
Slide 36 text
Okay, Let’s Do Something
Slide 37
Slide 37 text
Deactivate something
Slide 38
Slide 38 text
No content
Slide 39
Slide 39 text
theme/functions.php
Slide 40
Slide 40 text
No content
Slide 41
Slide 41 text
Order Matters
Slide 42
Slide 42 text
No content
Slide 43
Slide 43 text
.plugin-override { color: #fff !important } theme/style.css
Slide 44
Slide 44 text
theme/functions.php
Slide 45
Slide 45 text
No content
Slide 46
Slide 46 text
Quick Review
Slide 47
Slide 47 text
remove_action( ‘hook’, ‘function’ )
Slide 48
Slide 48 text
remove_action( ‘hook’, ‘function’ ) add_action( ‘hook’, ‘function’, 10 )
Slide 49
Slide 49 text
Hooks Open WordPress to Your Needs
Slide 50
Slide 50 text
A Few Examples
Slide 51
Slide 51 text
function excerpt_length_example( $length ) { return 15; } add_filter( 'excerpt_length', 'excerpt_length_example' );
Slide 52
Slide 52 text
function body_class_example( $classes ) { if( is_single() ) { foreach( get_the_category( get_the_ID() ) as $cat ) $classes[] = 'cat-' . $cat->category_nicename; } return $classes; } add_filter( 'body_class', 'body_class_example' );
Slide 53
Slide 53 text
function register_my_menus() { register_nav_menus( array( 'footer_menu' => __( 'Footer Menu', 'mytheme' ) ) ); } add_action( 'init', 'register_my_menus' );
Slide 54
Slide 54 text
function my_plugin_page() { add_options_page( 'Page Title', ‘Menu Title', 'manage_options', ‘plugin-slug', ‘my_plugin_page_init’ ); } add_action( 'admin_menu' , 'my_plugin_page' );
Slide 55
Slide 55 text
function publish_post_to_slack( ) { // Connect to Slack API } add_action( 'save_post', ‘publish_post_to_slack’ );
Slide 56
Slide 56 text
https://teamtreehouse.com/
Slide 57
Slide 57 text
Zac Gordon wp.zacgordon.com @zgordon https://teamtreehouse.com/learn/wordpress