Download pdf - WordPress Hooks

Transcript
Page 1: WordPress Hooks

Micah Wood @wpscholar https://wpscholar.com

WordPress Hooks

Page 2: WordPress Hooks

Actions

Page 3: WordPress Hooks

What is an action?An action is an event that occurs while WordPress is running.

Page 4: WordPress Hooks

Event Trigger“When Jill comes by, send her to the store for milk.”

Page 5: WordPress Hooks

Event Listener“When Jill comes by, send her to the store for milk.”

Page 6: WordPress Hooks

Do ActionEvent Trigger

Page 7: WordPress Hooks

Add ActionEvent Listener

Page 8: WordPress Hooks

Remove Action

Page 9: WordPress Hooks

Remove All Actions

Page 10: WordPress Hooks

Has Action

Page 11: WordPress Hooks

Did Action

Page 12: WordPress Hooks

Current Action

Page 13: WordPress Hooks

Doing Action

Page 14: WordPress Hooks

Filters

Page 15: WordPress Hooks

What is a filter?A filter is a collection of functions through which variables are passed.

Page 16: WordPress Hooks

Handoff“When Jack hands you his Rubix cube, solve it for him.”

Page 17: WordPress Hooks

Manipulation“When Jack hands you his Rubix cube, solve it for him.”

Page 18: WordPress Hooks

Apply FiltersHandoff

Page 19: WordPress Hooks

Add FilterManipulation

Page 20: WordPress Hooks

Remove Filter

Page 21: WordPress Hooks

Remove All Filters

Page 22: WordPress Hooks

Has Filter

Page 23: WordPress Hooks

Current Filter

Page 24: WordPress Hooks

Doing Filter

Page 25: WordPress Hooks

Pop Quiz

Page 26: WordPress Hooks

Explain the difference between an action and filter.An action allows you to do something.A filter allows you to do something to something.

Page 27: WordPress Hooks

Demo

Page 28: WordPress Hooks

Register Post Type

Page 29: WordPress Hooks

Change Body Classes

Page 30: WordPress Hooks

Alter Content

Page 31: WordPress Hooks

Resources

Page 32: WordPress Hooks

• http://docs.presscustomizr.com/article/26-wordpress-actions-filters-and-hooks-a-guide-for-non-developers

• http://blog.teamtreehouse.com/hooks-wordpress-actions-filters-examples • https://codex.wordpress.org/Plugin_API/Action_Reference • https://codex.wordpress.org/Plugin_API/Filter_Reference • https://www.smashingmagazine.com/2011/10/definitive-guide-wordpress-

hooks/ • https://wordpress.org/plugins/wp-hooker/ • https://wordpress.org/plugins/debug-bar-actions-and-filters-addon/ • http://wiki.theoctaneagency.com/doku.php?id=wordpress:list-hooked-

functions • https://pantheon.io/blog/tracing-wordpress-actions-and-filters

Resources

Page 33: WordPress Hooks

Micah Wood @wpscholar https://wpscholar.com

Questions?