Filters can operate on content snippets or on arrays.
Filters are the hooks that WordPress launches to modify text of various types before adding it to the database or sending it to the browser screen. Your plugin can specify that one or more of its PHP functions is executed to modify specific types of text at these times, using the Filter API.
To set up content for filtering, use the
Create the Hook
Apply filters attached to ‘custom_content_filter’ to $content. This would be typically added to a template file:
Create the filter and attach to the filter hook. Typically in custom functions file.
There are many built-in WordPress filters. For example, ‘the_content’ filters content after database retrieval and before printing to the screen. To use this filter, it’s simply a matter of passing the content. This can be very useful when fetching post content outside the loop using
get_the_content() - which returns unfiltered content.
Filter functions can be added using the
add_filter() function. For example, this function prepends a post thumbnail to the $content passed in to the ‘the_content’ filter - which is usually the post content:
From WP Codex.
comments powered by Disqus