hello friends welcome to my another
video tutorial on wordpress and
Woocommerce for intermediate and advanced users in this video tutorial i am going
to discuss about filter hooks as you
know there are two types of hooks in
wordpress action hooks and filter hooks
regarding action hooks i have already
covered it in my previous tutorial and
if you haven't watched that tutorial
kindly check the link in description and
do watch it to understand about action
hooks so what are the filter looks
basically filter hooks are same as the
action hooks the main and key difference
between action and filter hooks is that
filter hooks are used to filter the
contents as you want them for example if
you added an action using add action and
before it outputs anything with that
action you want to filter its content by
styling it or by jacking it before
saving it into database or showing it in
the browser soon i will show you some
live examples so basically we should
understand there are three types of
filter hooks as there are three types of
action oops first is add filter hook
this hook will be used to add a filter
to a particular action or number of
actions or you can filter particular
contents number to apply filters keep in
mind add filter have known as where
apply filters is not filter its filters
it will apply those filters which you
have created using add filter hoops
number three remove filter hook this
hook will remove the functionality added
by add filter or applied by using apply
filters hook so let's get some live
examples of filter hooks and see it in
action
so let's take some live example of
filter hopes if you don't know in this
tutorial i am using twenty 2017 child
theme which i have created using a
plug-in named child theme configurator
if you haven't watched my video about
how to create child theme you can find
and watch it how to create child him
manually and how to create child teams
using child team configurator plugin so
I have also override the content of a
single post so here it will be single
post which I am going to apply some
actions and filters so in my last
actions in my last tutorial where i show
how to use action books i have created
an action and i will use the same action
i have applied here which is do action
my own action so i will copy this name
and in my function dot PHP i will add
action name it same and create a
function by action function then i will
create this function my own action
function and i'm going to echo the hello
world simple save it and run it now
suppose i want this hello world color to
be red color i can do it easily by
putting a span tag here spawn style is
equal to color red and here end span so
what will happen if i run it again you
see color is red but what
if you want to change this color they
have to remove this action add their own
action and then change the color of this
text but they are the static text so
they have to write it again is called
you can say it is duplication so to
avoid this we will apply to filter on it
one we will change the color to red the
second we will also put it an h2 tag so
first let's see how can we change color
without modifying the action and using
filter hoops add as you know we will use
add filter my own filter and my own
filter function simple names you can
name them whatever you want but as I
told you remember don't give them a name
which is already existed so it will
create some problems for you so my all
filter function and Here I am going to
pass a parameter text on which we will
performing the filter so what it will
return it will return same thing this
one and let me copy copy and paste it
here and remove the text from here man
then lift on this return this text with
same so whatever text will come to this
filter it will be color right another we
can add another filter to it add filter
my pound filter by another filter action
so as you see I have created another
function let me create this one first
then I will explain it to you what it
will return it will return
the same thing x 2 dot txt dot H 2 solo
here comes the role of priority if I
give priority to my another filter
function then it will be displayed like
this it's farm this is just I am showing
you style color red edge to text here
whatever text is here /h to flash spa so
this is how it will work and if someone
i have given as to a different color
that this color red will not be applied
to this text so what we need to do we
need to move these h2 before spawn and
this as two so you want to display it
like this this is how one to display so
then whatever is h2 color half it will
be overwritten by this color and it will
have this text in red color although i
have written the both functions in in
the same inner in an order so they will
run in in order having same priority so
it will run first this and then it will
run this function and the color it will
be output in this one but here we will
use the priority of both priority for
both functions so i have used five and
ten so but i haven't applied it i have
added it but i haven't applied it on the
t stag so how to apply it apply filters
you person it's a plural not singular
filter its apply filters because it will
apply both filters
my own filter comma so here you will
write attacks anything you want to pick
down like you can put a PO page post
titles you can put a page title whatever
you are like you can access your Global
post and then you can put the post title
here as well no problem with that so my
own filter and hello world text simple
and now random single post and you see
it have h2 as an outer and spawn as the
inner text what if I do 10 here and five
here so let's see what the difference it
will make you see the red color has not
been applied although it's in the color
red but because the priority has been
changed so the spawn comes first then
comes the h2 inside and it over edge to
have different color settings so it
doesn't apply this color red just change
the five and five spot and now what will
happen it will run the same priority as
in they are defined in order so when to
use priority when you don't know in
which order those functions are defined
in an addict class or in another file so
then you use priority at which function
you want to run or which filter you want
to run first to filter the content there
is another thing in it the advantage of
using this filter that suppose we don't
want edge to tag yes we don't want to
put h2 tag with the hello world text and
we want just the spawn what we are going
to do we don't need to remove this
function as we will choose remove filter
keep in mind is singular not plural here
my arm
so which filter you want to remove you
don't want to see h2 tag okay good
remove this comma put here and give the
same priority as you give an injured
advil direction here is five or so I
gave it five here and then they ran that
then whoa you see the edge to filter is
gone and it's only using spa intact so
friends with the help of filters and
actions you can create themes and
plugins and give the user access to use
their these filters and actions to
modify the contents without modifying
the original file so that if you later
you give an update it will not be
overridden by the changes if for example
this text is static text and we have
statically put the spawn and h2 what
will happen that if user want the color
to be yellow suppose the color wants to
be yellow so what you gonna do is simply
remove this own filter color in your
child theme up or not in the parent
theme in the child thing or if you have
given the success in the plugin then
they will do it in their home child in
even that so then if the parent theme
updated this function will not be
removed so remove filter this because we
are going to change the color to yellow
so to move and keep the same priority
and you will see that spawn tag will be
removed and it will only have the h2
color h2 so now you want to change it to
yellow color so create another filter
and your child can add filter and sorry
I let me copy this one copy paste and
then choose add filter my own filter my
own filter function number two so it
will you want mix
with atoms using the same red color
function so it will run the same
function if i don't use any unique name
so function to hear text same parameters
and now copy from the source file you
can copy paste it here in your child in
change the color yellow and no need to
do anything no need to change anywhere
else it will perform the same action and
change this color to yellow sorry let me
see what oh it is sorry the priority I
haven't given so you see the priority is
not given here so I have to move the
filter and add the function again so I
have to give it priority before doing
this another function because I removed
it and if after removing it executed
this function after that it executed
this small chain so I have to give it
like let's give it to as the name
suggests let's give it to and run it
again and you see by giving it priority
to I'm telling it don't run this file
function first run this priority to then
run this file so that is why mostly we
use here the high higher numbers when
developer like this we will put it here
15 and we'll put it here 15 we'll put it
815 and here we will put the same thing
will happen you see the same thing same
output will happen so this is how you
are going to use filter hooks I hope you
have liked my tutorial please do comment
and if you need any help regarding
wordpress r vu commerce and if you want
me to make em tutorial any video
tutorial
regarding your needs do tell me and I
will try my best to create is the video
thank you for watching and please do
subscribe to my channel as I'm daily
going to update new videos until there
is WordPress and for commerce and until
there is I or there is me thank you very
much once again hope you liked my
tutorial bye
