Home > Questions > What does apply_filters(...) actually do in WordPress?

What does apply_filters(...) actually do in WordPress?

Answered
1
1

I’m trying to understand some of the function in WordPress, but I can’t get my head around what apply_filters(…) actually does.

Is someone able to clear this up for me with a few examples?

NOTE: This question was originally posted at StackOverflow.com by Tim

  • demo
    commenttttttt
  • You must to post comments
Good Answer
1
0

apply_filters($tag, $value) passes the ‘value’ argument to each of the functions ‘hooked’ (using add_filter) into the specified filter ‘tag’. Each function performs some processing on the value and returns a modified value to be passed to the next function in the sequence.

For example, by default (in Wordpress 2.9) the the_content filter passes the value through the following sequence of functions:

  • wptexturize
  • convert_smilies
  • convert_chars
  • wpautop
  • shortcode_unautop
  • prepend_attachment
  • do_shortcode

NOTE: This answer was originally posted at StackOverflow.com by Richard M

  • You must to post comments
1
1

Here’s what I’m gleaning, upon considering the most popular answer and additional resources:

  • $tag seems to be a synonym for the name of the hook. (That’s not particularly intuitive to me.)
  • the_content is an example of a hook, of the “filter” type.
  • the_content hook consists of multiple filters.
  • Filters modify data. They basically filter the database, changing the data before the users view it.
  • A common use of apply_filters(), for instance, is to apply the_content filters to $content. In this instance, double returns will convert to <p> tags, smiley faces will convert to icons, etc.
  • “the_content” is a hook, while “the_content()” is a function.

NOTE: This answer was originally posted at StackOverflow.com by Marjorie Roswell

  • You must to post comments
0
0

In the most basic terms, apply_filters is used to initialise a filter hook… add_filter assigns a new function to hooks that have already been created.

NOTE: This answer was originally posted at StackOverflow.com by Steve

  • demo
    psum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullam
  • You must to post comments
0
0

psum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullam

  • You must to post comments
0
0

youtube

  • demo
    fuuu
  • You must to post comments
0
0

youtube iframe

  • You must to post comments
0
0

youtube iframe

  • You must to post comments
0
0

youtube

  • You must to post comments
Showing 8 results
Your Answer
Guest Author
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website
CAPTCHA*
Enter the characters shown on the image.