際際滷

際際滷Share a Scribd company logo
What the Hook
What YOU should know about
WordPress Actions & Filters
M u h a m m a d K a s h i f
m e @ K a s h i f . i o
Intro
Muhammad Kashif
F o u n d e r & C E O - M e s h P r o s
M a s t e r T r a i n e r - e R o z g a a r
O r g a n i z e r  W C L a h o r e 2 0 1 9
How do you make changes
Core/Themes/Plugins
What areHooks?
What areHooks?
Hooks are a way for one piece of
code to interact/modify another
piece of code.
What areHooks?
Hooks enable us to literally hook into parts of
the WordPress page lifecycle to retrieve, insert,
or modify data, or they allow us to take certain
actions behind the scenes. 
-TOM MCFARLIN @ TUTSPLUS
What areHooks?
Types
Actions
Filters
Actions
Functions that are executed when
something happens in WordPress.
For example:
 When a post is published
 Before the header is loaded
Declared with add_action
Actions
Functions that are executed when
something happens in WordPress.
You can attach custom code at theseevents:
Actions
Functions that are executed when
something happens in WordPress.
You can attach custom code at theseevents:
 When a post is published, send me anemail
Actions
Functions that are executed when
something happens in WordPress.
You can attach custom code at theseevents:
 When a post is published, send me anemail
 When the header is loaded, add some css
Functions that WordPress passes
data through before it is sent tothe
browser or database.
Filters
Functions that WordPress passes
data through before it is sent tothe
browser or database.
For example:
 When the post title isdisplayed
 When the author url isoutput
Declared with add_filter
Filters
Filters
Functions that WordPress passes
data through before it is sent tothe
browser or database.
You can attach custom code at theseevents:
Filters
Functions that WordPress passes
data through before it is sent tothe
browser or database.
You can attach custom code at theseevents:
 When the post title is displayed, add something
Which Hook should Iuse?
Actions FiltersOR
Which Hook should Iuse?
ORActions
Use an action when
you want something
to happen
Filters
Use a filter when you
want to change
something
Info about hooks
https://codex.wordpress.org/Plugin_API
Example Actions
wp_enqueue_scripts
create_category
publish_page
the_title
excerpt_more
the_content
Example Filters
How to construct a hook
How to construct a hook
tag - the name of the action to attach code to
your_function - the name of your custom function
$priority -the order that the functions are executed
$args - the number of arguments sent to your function
Breaking it down
Some Poetry
Nog vragen ?
me@kashif.io
Contacts
@imQashif

More Related Content

WordPress Hooks (Actions & Filters)