As you can see, the default excerpt length is still 150, but we’ve also applied
some filters to it. A filter allows you to write a function that modifies the
value of something — in this case, the excerpt’s length. The name (or tag) of
this filter is excerpt_length, and if no functions are attached to it, then its
value will remain 150. Let’s see how we can now use this to modify the
default value.
First, we have defined a function that does nothing but return a number. At
this point, nothing is using the function, so let’s tell WordPress that we want
to hook this into the excerpt_length filter.
We’ve successfully changed the default excerpt length in WordPress,
without touching the original function and without even having to write a
custom excerpt function. This will be extremely useful, because if you
always want excerpts that are 200 characters long, just add this as a filter
and then you won’t have to specify it every time.
Suppose you want to tack on some more text, like “Read on,” to the end of
the excerpt. We could modify our original function to work with a hook and
then tie a function to that hook, like so:
As you can see, the default excerpt length is still 150, but we’ve also appliedsome filters to it. A filter allows you to write a function that modifies thevalue of something — in this case, the excerpt’s length. The name (or tag) ofthis filter is excerpt_length, and if no functions are attached to it, then itsvalue will remain 150. Let’s see how we can now use this to modify thedefault value.First, we have defined a function that does nothing but return a number. Atthis point, nothing is using the function, so let’s tell WordPress that we wantto hook this into the excerpt_length filter.We’ve successfully changed the default excerpt length in WordPress,without touching the original function and without even having to write acustom excerpt function. This will be extremely useful, because if youalways want excerpts that are 200 characters long, just add this as a filterand then you won’t have to specify it every time.Suppose you want to tack on some more text, like “Read on,” to the end ofthe excerpt. We could modify our original function to work with a hook andthen tie a function to that hook, like so:
การแปล กรุณารอสักครู่..
