WordPress Filters Cheat Sheet
This cheat sheet explores a fundamental concept in WordPress development: filters.
In WordPress, filters enable developers to intercept and modify data as a WordPress page is loading, before sending it to the browser or saving it to the database.
Understanding how filters work isn’t all that easy, partly because the concept is difficult to visualize, and also because filters are often confused with WordPress actions. Yet, it’s an important concept to master because filters are one of the most common ways developers interact with WordPress.
For these reasons, this filter cheat sheet is ideal for those new to working with filters. This cheat sheet provides an in-depth understanding of what filters do and how they work, and provides a quick reference guide for using filters in WordPress development.
WordPress Basics: Hooks & Functions
Let’s start with a basic overview of how WordPress works to help you understand the context of where filters fit in WordPress core code .
A WordPress page is made up of a whole bunch of functions and database queries, with the WordPress core code and the theme working together to output text, images, stylesheets, and other resources. The browser interprets all of this data as it’s processing and then displays it all together as one web page.
Hooks
Throughout the core code are hooks, which are basically placeholders developers can use to “hook” into WordPress and insert their own custom code for processing as a page is loading.
There are two types of hooks: filters and actions:
Filter hooks let you intercept and modify data as it’s being processed. Basically, filters let you manipulate data coming out of the database before going to the browser, or coming from the browser before going into the database. For example, you might want to do something as simple as prepend a word to the title of all your blog posts, or filter out bad language in post comments.
Action hooks, on the other hand, lets you add extra functionality at specific points in the processing and loading of a page. For example, you might want to add a promotional pop-up message to your page or display a copyright message in the footer.
Basically, filter hooks change stuff and action hooks do stuff.
WordPress provides a huge stack of built-in filter hooks for use in WordPress development. However, you can also create your own filter hooks using the apply_filters()
function, which I’ll show you how to use shortly.
Functions
In order to use WordPress hooks, you need to write a function.
A function is a piece of custom code that specifies how something will happen. For example, you could code a function to query data, output content, or perform many other tasks.
In WordPress, if you want to “change stuff” in your theme, you need to code a filter function that uses a filter hook.
Using Filters: Example
There are three basic steps involved in adding your own filters to WordPress:
- Coding a PHP function that filters the data.
- Hooking into and existing and appropriate filter hook in WordPress by calling
add_filter()
. - Putting your PHP function in a WordPress/plugin file and activating it.
1. Creating a Filter Function
Say you wanted to filter out bad language in blog post comments on your site.
The first step is to code a function that filters your WordPress comments and either removes the bad language or replaces it with other words. For example, you could put together a list of bad words you don’t want displayed on your site and replace them with a censor flag by creating the following PHP function:
function filter_bad_languge( $content ) { $badwords = array('fopdoogle', 'gobermouch', 'yaldson'); $content = str_ireplace( $badwords, '{censored}', $content ); return $content; }
Here’s a breakdown of the code above:
- This is the code that hooks into the filter hook. It’s easy to spot a custom function as it always starts with
function()
. filter_badlanguge
is the name of the filter function.$content
is the function’s single argument.$badwords = array('fopdoogle','gobermouch','yaldson');
is the first work the function carries out. Specifically, it creates an array called$badwords
and adds the words fopdoogle, gobermouch, and yaldson to that array.str_ireplace
loops through your content, searching for any of the words stored in the$badwords
array, replacing them with “{censored},” and then returning them to$content
.- return is very important here: it’s how the function returns the filtered content back to WordPress core.
2. Using a Filter Hook
Once you’ve coded your filter, you need to “hook” it into WordPress core using a hook call. To do this, you use add_filter()
:
add_filter( 'comment_text', 'filter_bad_language' );
Here’s what the above code means:
comment_text
is the name of the filter hook provided by WordPress, which we want our filter to apply to, i.e. we want our filter to work on blog post comments.filter_badlanguage
is the name of the function that we want to use for filtering.
3. Installing and Activating a Filter
The last step in order to get your filter hook working is to add your function and add_filter()
call together in a PHP file. Continuing our bad language example, we would combine the code like so:
function filter_bad_languge( $content ) { $badwords = array('fopdoogle', 'gobermouch', 'yaldson'); $content = str_ireplace( $badwords, '{censored}', $content ); return $content; } add_filter( 'comment_text', 'filter_bad_language' );
Typically, you would either add your function and call to your theme’s functions.php file using a child theme, or create a new plugin. How to do this is beyond the scope of this article, but I highly encourage you read up how to create a child theme and how to create a plugin in the WordPress Developer Handbook.
If you decide to use your function in a plugin, you’ll need to install and activate your newly created plugin in order for your code to work.
Using Custom Filter Hooks
A useful feature in WordPress plugin development is the ability to create custom hooks for use in your plugins so that other developers can extend and modify them.
Custom hooks can be created and called in the same way that WordPress core hooks are created and called.
There are two basic steps involved in creating and using your own custom filter hooks:
- Adding a custom filter hook to an existing function using
apply_filters()
. - You (or another developer) coding a custom function that hooks into the custom filter hook.
Creating a Filter Hook
To create a custom hook, you add apply_filters()
in your code where you would like to place a hook.
For example, using the bad language example from above, let’s say we wanted to allow other developers to add new words to be censored. You could do this by updating the function to include a filter:
function filter_bad_languge( $content ) { $badwords = array('fopdoogle', 'gobermouch', 'yaldson'); $badwords = apply_filters('add_bad_language_filter', $badwords ); $content = str_ireplace( $badwords, '{censored}', $content ); return $content; }
add_badlanguage_filter
becomes a filter hook that can be used to modify the list of censored words, with $content
being the default value to be returned.
Using a Custom Filter Hook
So what happens when another developer uses this custom filter? Well, they can remove bad words, change their names, add new words, etc. In this example, I simply want to add a new censored word:
function add_new_bad_words($profanities) { $extra_bad_words = array('sard', 'bescumber'); $profanities = array_merge($extra_bad_words, $profanities); return $profanities; } add_filter('add_bad_language_filter', 'add_new_bad_words');
When the add_new_bad_words function displays the list of bad words, we’ll now see this:
- fopdoogle
- gobermouch
- yaldson
- sard
- bescumber
(In case you haven’t already googled these unusual sounding words, they’re old English curse words.)
Naming Conflicts
Since you can give custom hooks any name you want, it’s important that you prefix your hook names to avoid conflicts with other plugins.
For example, a filter hook simply called post_body would be more likely to be used by another developer. This means if a WordPress user installs and activates your plugin and another developers plugin with hooks using similar names, it would lead to bugs.
It’s recommended you prefix your custom hooks with a shortened version of your name or company, i.e. wbb_add_bad_language_filter
.
Unhooking Functions From Filters
In some cases, you may want your plugin to disable a filter built into WordPress or used by a conflicting plugin. You can do this by using remove_filter()
.
The remove_filter()
function has three parameters: the name of the filter hook, the name of the function which should be removed, and the priority (which is only mandatory if a priority was set when the function was originally hooked to the filter).
So to remove the add_new_bad_words I created earlier, I would use:
remove_filter( 'add_new_bad_words', 'add_bad_language_filter');
The code output would then revert to the value I specified in my original apply_filters()
function.
Filter Hook Reference Guide
WordPress has hundreds of built-in filter hooks that developers can use to hook into the core code.
The WordPress Codex provides guidance on how to use filter hooks, which it lists using the following categories:
- Post, Page, and Attachment (Upload) Filters
- Comment, Trackback, and Ping Filters
- Category and Term Filters
- Link Filters
- Date and Time Filters
- Author and User Filters
- Blogroll Filters
- Blog Information and Option Filters
- General Text Filters
- Administrative Filters
- Rich Text Editor Filters
- Template Filters
- Registration & Login Filters
- Redirect/Rewrite Filters
- WP_Query Filters
- Media Filters
- Advanced WordPress Filters
- Widgets
- Admin Bar
Many of these filter hooks are split into two sub-categories: database reads and database writes. This depends on whether a function is reading from the database prior to displaying content on a page, or you’re writing code prior to saving data to the database.
Using with hooks in WordPress started with working out what hook you need to “hook” your code to and then writing a function to modify the data you need.
Post, Page, and Attachment (Upload) Filters
Database Reads
attachment_fields_to_edit
– Applied to form fields to be displayed when editing an attachment.attachment_icon
– Applied to the icon for an attachment in theget_attachment_icon
function.attachment_innerHTML
– applied to the title to be used for an attachment if there is no icon, in theget_attachment_innerHTML
function.author_edit_pre
– Applied to post author prior to display for editing.body_class
– Applied to the classes for the HTML<body>
element. Called in the get_body_class function.content_edit_pre
– Applied to post content prior to display for editing.content_filtered_edit_pre
– Applied to post content filtered prior to display for editing.excerpt_edit_pre
– Applied to post excerpt prior to display for editing.date_edit_pre
– Applied to post date prior to display for editing.date_gmt_edit_pre
– Applied to post date prior to display for editing.get_attached_file
– Applied to the attached file information retrieved by theget_attached_file
function.get_enclosed
– Applied to the enclosures list for a post by the get_enclosed function.get_pages
– Applied to the list of pages returned by the get_pages function.get_pung
– Applied to the list of pinged URLs for a post by theget_pung
function.get_the_archive_title
– Applied to the archive’s title in the get_the_archive_title function.get_the_excerpt
– Applied to the post’s excerpt in the get_the_excerpt function.get_the_guid
– Applied to the post’s GUID in theget_the_guid
function.get_to_ping
– Applied to the list of URLs to ping for a post by theget_to_ping
function.icon_dir
– Applied to the template’s image directory in several functions.icon_dir_uri
– Applied to the template’s image directory URI in several functions. Basically allows a plugin to specify that icons for MIME types should come from a different location.image_size_names_choose
– Applied to the list of image sizes selectable in the Media Library. Commonly used to make custom image sizes selectable.mime_type_edit_pre
– Applied to post mime type prior to display for editing.modified_edit_pre
– Applied to post modification date prior to display for editing.modified_gmt_edit_pre
– Applied to post modification gmt date prior to display for editing.no_texturize_shortcodes
– Applied to registered shortcodes. Can be used to exempt shortcodes from the automatic texturize function.parent_edit_pre
– Applied to post parent id prior to display for editing.password_edit_pre
– Applied to post password prior to display for editing.post_class
– Applied to the classes of the outermost HTML element for a post. Called in theget_post_class
function. Filter function arguments: an array of class names, an array of additional class names that were added to the first array, and the post ID.pre_kses
– Applied to various content prior to being processed/sanitized by KSES. This hook allows developers to customize what types of scripts/tags should either be allowed in content or stripped.prepend_attachment
– Applied to the HTML to be prepended by the prepend_attachment function.protected_title_format
– Used to the change or manipulate the post title when the post is password protected.private_title_format
– Used to the change or manipulate the post title when its status is private.sanitize_title
– Applied to a post title by thesanitize_title
function, after stripping out HTML tags.single_post_title
– Applied to the post title when used to create a blog page title by thewp_title
andsingle_post_title
functions.status_edit_pre
– Applied to post status prior to display for editing.the_content
– Applied to the post content retrieved from the database, prior to printing on the screen (also used in some other operations, such as trackbacks).the_content_rss
– Applied to the post content prior to including in an RSS feed. (Deprecated)the_content_feed
– Applied to the post content prior to including in an RSS feed.the_editor_content
– Applied to post content before putting it into a rich editor window.the_excerpt
– Applied to the post excerpt (or post content, if there is no excerpt) retrieved from the database, prior to printing on the screen (also used in some other operations, such as trackbacks).the_excerpt_rss
– Applied to the post excerpt prior to including in an RSS feed.the_password_form
– Applied to the password form for protected posts.the_tags
– Applied to the tags retrieved from the database, prior to printing on the screen.the_tags
– Applied to the post title retrieved from the database, prior to printing on the screen (also used in some other operations, such as trackbacks).the_title_rss
– Applied to the post title before including in an RSS feed (after first filtering withthe_title
.title_edit_pre
– Applied to post title prior to display for editing.type_edit_pre
– Applied to post type prior to display for editing.wp_dropdown_pages
– Applied to the HTML dropdown list of WordPress pages generated by thewp_dropdown_pages
function.wp_list_pages
– Applied to the HTML list generated by thewp_list_pages
function.wp_list_pages_excludes
– Applied to the list of excluded pages (an array of page IDs) in thewp_list_pages
function.wp_get_attachment_metadata
– Applied to the attachment metadata retrieved by thewp_get_attachment_metadata
function.wp_get_attachment_thumb_file
– Applied to the attachment thumbnail file retrieved by thewp_get_attachment_thumb_file
function.wp_get_attachment_thumb_url
– Applied to the attachment thumbnail URL retrieved by thewp_get_attachment_thumb_URL
function.- wp_get_attachment_url – Applied to the attachment URL retrieved by the
wp_get_attachment_url
function. wp_mime_type_icon
– Applied to the MIME type icon for an attachment calculated by thewp_mime_type_icon
function.wp_title
– Applied to the blog page title before sending to the browser in thewp_title
function.
Database Writes
add_ping
– Applied to the new value of the pinged field on a post when a ping is added, prior to saving the new information in the database.attachment_fields_to_save
– Applied to fields associated with an attachment prior to saving them in the database. Called in themedia_upload_form_handler
function. Filter function arguments: an array of post attributes, an array of attachment fields including the changes submitted from the form.attachment_max_dims
– Applied to the maximum image dimensions before reducing an image size. Filter function input (and return value) is either false (if no maximum dimensions have been specified) or a two-item list (width, height).category_save_pre
– Applied to post category comma-separated list prior to saving it in the database (also used for attachments).comment_status_pre
– Applied to post comment status prior to saving it in the database (also used for attachments).content_filtered_save_pre
– Applied to filtered post content prior to saving it in the database (also used for attachments).content_save_pre
– Applied to post content prior to saving it in the database (also used for attachments).excerpt_save_pre
– Applied to post excerpt prior to saving it in the database (also used for attachments).image_save_pre
(deprecated) – Use image_editor_save_pre instead.jpeg_quality
(deprecated) – Usewp_editor_set_quality
orWP_Image_Editor::set_quality()
instead.name_save_pre
(Deprecated) – Applied to post name prior to saving it in the database (also used for attachments).phone_content
– Applied to the content of a post submitted by email, before saving.ping_status_pre
– Applied to post ping status prior to saving it in the database (also used for attachments).post_mime_type_pre
– Applied to the MIME type for an attachment prior to saving it in the database.status_save_pre
– Applied to post status prior to saving it in the database.thumbnail_filename
– Applied to the file name for the thumbnail when uploading an image.title_save_pre
– Applied to post title prior to saving it in the database (also used for attachments).update_attached_file
– Applied to the attachment information prior to saving in post metadata in the update_attached_file function. Filter function arguments: attachment information, attachment ID.wp_create_thumbnail
(deprecated)wp_delete_file
– Applied to an attachment file name just before deleting.wp_generate_attachment_metadata
– Applied to the attachment metadata array before saving in the database.wp_save_image_file
(deprecated) –Use
wp_save_image_editor_file instead.wp_thumbnail_creation_size_limit
– Applied to the size of the thumbnail when uploading an image. Filter function arguments: max file size, attachment ID, attachment file name.wp_thumbnail_max_side_length
– Applied to the size of the thumbnail when uploading an image. Filter function arguments: image side max size, attachment ID, attachment file name.wp_update_attachment_metadata
– Applied to the attachment metadata just before saving in thewp_update_attachment_metadata
function. Filter function arguments: meta data, attachment ID.
Comment, Trackback, and Ping Filters
Database Reads
comment_excerpt
applied to the comment excerpt by the comment_excerpt function. See alsoget_comment_excerpt
.comment_flood_filter
– Applied when someone appears to be flooding your blog with comments. Filter function arguments: already blocked (true/false, whether a previous filtering plugin has already blocked it; set to true and return true to block this comment in a plugin), time of previous comment, time of current comment.comment_post_redirect
– Applied to the redirect location after someone adds a comment. Filter function arguments: redirect location, comment info array.comment_text
– Applied to the comment text before displaying on the screen by thecomment_text
function, and in the admin menus.comment_text_rss
– Applied to the comment text prior to including in an RSS feed.comments_array
– Applied to the array of comments for a post in the comments_template function. Filter function arguments: array of comment information structures, post ID.comments_number
– Applied to the formatted text giving the number of comments generated by the comments_number function. See alsoget_comments_number
.get_comment_excerpt
– Applied to the comment excerpt read from the database by theget_comment_excerpt
function (which is also called bycomment_excerpt
. See alsocomment_excerpt
.get_comment_ID
– Applied to the comment ID read from the global$comments
variable by theget_comment_ID
function.get_comment_text
– Applied to the comment text of the current comment in theget_comment_text
function, which is also called by thecomment_text
function.get_comment_type
– Applied to the comment type (“comment”, “trackback”, or “pingback”) by theget_comment_type
function (which is also called bycomment_type
).get_comments_number
– Applied to the comment count read from the$post
global variable by theget_comments_number
function (which is also called by the comments_number function; see also comments_number filter).post_comments_feed_link
– Applied to the feed URL generated for the comments feed by thecomments_rss
function.
Database Writes
comment_save_pre
– Applied to the comment data just prior to updating/editing comment data. Function arguments: comment data array, with indices “comment_post_ID
“, “comment_author
“, “comment_author_email
“, “comment_author_url
“, “comment_content
“, “comment_type
“, and “user_ID
“.pre_comment_approved
– Applied to the current comment’s approval status (true/false) to allow a plugin to override. Return true/false and set first argument to true/false to approve/disapprove the comment, and use global variables such as$comment_ID
to access information about this comment.pre_comment_content
– Applied to the content of a comment prior to saving the comment in the database.preprocess_comment
– Applied to the comment data prior to any other processing, when saving a new comment in the database. Function arguments: comment data array, with indices “comment_post_ID
“, “comment_author”, “comment_author_email
“, “comment_author_url
“, “comment_content
“, “comment_type
“, and “user_ID
“.wp_insert_post_data
– Applied to modified and unmodified post data inwp_insert_post()
prior to update or insertion of post into database. Function arguments: modified and extended post array and sanitized post array.
Category and Term Filters
Database Reads
category_description
– Applied to the “description” field categories by thecategory_description
andwp_list_categories
functions. Filter function arguments: description, category ID when called fromcategory_description
; description, category information array (all fields from the category table for that particular category) when called fromwp_list_categories
.category_feed_link
– Applied to the feed URL generated for the category feed by theget_category_feed_link
function.category_link
– Applied to the URL created for a category by theget_category_link
function. Filter function arguments: link URL, category ID.get_ancestors
– Applied to the list of ancestor IDs returned by theget_ancestors
function (which is in turn used by many other functions). Filter function arguments: ancestor IDs array, given object ID, given object type.get_categories
– Applied to the category list generated by theget_categories
function (which is in turn used by many other functions). Filter function arguments: category list, get_categories options list.get_category
– Applied to the category information that the get_category function looks up, which is basically an array of all the fields in WordPress’s category table for a particular category ID.list_cats
– Called for two different purposes: 1. thewp_dropdown_categories
function uses it to filter the show_option_all andshow_option_none
arguments (which are used to put options “All” and “None” in category drop-down lists). No additional filter function arguments; and 2: thewp_list_categories
function applies it to the category names. Filter function arguments: category name, category information list (all fields from the category table for that particular category).list_cats_exclusions
– Applied to the SQL WHERE statement giving the categories to be excluded by the get_categories function. Typically, a plugin would add to this list, in order to exclude certain categories or groups of categories from category lists. Filter function arguments: excluded category WHERE clause,get_categories
options list.single_cat_title
– Applied to the category name when used to create a blog page title by thewp_title
andsingle_cat_title
functions.- the_category – Applied to the list of categories (an HTML list with links) created by the
get_the_category_list
function. Filter function arguments: generated HTML text, list separator being used (empty string means it is a default LI list), parents argument toget_the_category_list
. the_category_rss
– Applied to the category list (a list of category XML elements) for a post by the get_the_category_rss function, before including in an RSS feed. Filter function arguments are the list text and the type (“rdf” or “rss” generally).wp_dropdown_cats
– Applied to the drop-down category list (a text string containing HTML option elements) generated by thewp_dropdown_categories
function.wp_list_categories
– Applied to the category list (an HTML list) generated by thewp_list_categories
function.wp_get_object_terms
– Applied to the list of terms (an array of objects) generated by thewp_get_object_terms
function, which is called by a number of category/term related functions, such asget_the_terms
andget_the_category
.
Database Writes
pre_category_description
– Applied to the category description prior to saving in the database.wp_update_term_parent
– Filter term parent before update to term is applied, hook to this filter to see if it will cause a hierarchy loop.edit_terms
– (actually an action, but often used like a filter) hooked in prior to saving taxonomy/category change in the databasepre_category_name
– Applied to the category name prior to saving in the database.pre_category_nicename
– Applied to the category nice name prior to saving in the database.
Link Filters
These hooks let you filter links related to posts, pages, archives, and feeds.
attachment_link
– Applied to the calculated attachment permalink by theget_attachment_link
function. Filter function arguments: link URL, attachment ID.author_feed_link
– Applied to the feed URL generated for the author feed by theget_author_rss_link
function.- author_link – Applied to the author’s archive permalink created by the
get_author_posts_url
function. Filter function arguments: link URL, author ID, author’s “nice” name. Note thatget_author_posts_url
is called within functionswp_list_authors
andthe_author_posts_link
. comment_reply_link
– Applied to the link generated for replying to a specific comment by theget_comment_reply_link
function which is called within functioncomments_template
. Filter function arguments: link (string), custom options (array), current comment (object), current post (object).day_link
– Applied to the link URL for a daily archive by theget_day_link
function. Filter function arguments: URL, year, month number, day number.feed_link
– Applied to the link URL for a feed by theget_feed_link
function. Filter function arguments: URL, type of feed (e.g. “rss2”, “atom”, etc.).get_comment_author_link
– Applied to the HTML generated for the author’s link on a comment, in theget_comment_author_link
function (which is also called by comment_author_link. Action function arguments: user name.get_comment_author_url_link
– Applied to the HTML generated for the author’s link on a comment, in theget_comment_author_url_link
function (which is also called bycomment_author_link
).month_link
– Applied to the link URL for a monthly archive by theget_month_link
function. Filter function arguments: URL, year, month number.page_link
– Applied to the calculated page URL by the get_page_link function. Filter function arguments: URL, page ID. Note that there is also an internal filter called_get_page_link
that can be used to filter the URLS of pages that are not designated as the blog’s home page (same arguments). Note that this only applies to WordPress pages, not posts, custom post types, or attachments.post_link
– Applied to the calculated post permalink by the get_permalink function, which is also called by the the_permalink,post_permalink
,previous_post_link
, andnext_post_link
functions. Filter function arguments: permalink URL, post data list. Note that this only applies to WordPress default posts, and not custom post types (nor pages or attachments).post_type_link
– Applied to the calculated custom post type permalink by theget_post_permalink
function.the_permalink
– Applied to the permalink URL for a post prior to printing by functionthe_permalink
.year_link
– Applied to the link URL for a yearly archive by theget_year_link
function. Filter function arguments: URL, year.tag_link
– Applied to the URL created for a tag by theget_tag_link
function. Filter function arguments: link URL, tag ID.term_link
– Applied to the URL created for a term by theget_term_link
function. Filter function arguments: term link URL, term object and taxonomy slug.
Date and Time Filters
get_comment_date
– Applied to the formatted comment date generated by theget_comment_date
function (which is also called bycomment_date
).get_comment_time
– Applied to the formatted comment time in the get_comment_time function (which is also called by comment_time).get_the_modified_date
– Applied to the formatted post modification date generated by theget_the_modified_date
function (which is also called by thethe_modified_date
function).get_the_modified_time
– Applied to the formatted post modification time generated by theget_the_modified_time
andget_post_modified_time
functions (which are also called by the the_modified_time function).get_the_time
– Applied to the formatted post time generated by the get_the_time andget_post_time
functions (which are also called by the the_time function).the_date
– Applied to the formatted post date generated by the the_date function.the_modified_date
– Applied to the formatted post modification date generated by thethe_modified_date
function.the_modified_time
– Applied to the formatted post modification time generated by thethe_modified_time
function.the_time
– Applied to the formatted post time generated by thethe_time
function.the_weekday
– Applied to the post date weekday name generated by thethe_weekday
function.the_weekday_date
– Applied to the post date weekday name generated by thethe_weekday_date
function. Function arguments are the weekday name, before text, and after text (before text and after text are added to the weekday name if the current post’s weekday is different from the previous post’s weekday).
Author and User Filters
login_body_class
– Allows filtering of the body class applied to the login screen inlogin_header()
.login_redirect
– Applied to theredirect_to
post/get variable during the user login process.user_contactmethods
– Applied to the contact methods fields on the user profile page. (old page is here:contactmethods
)update_(meta_type)_metadata
– Applied before a (user) metadata gets updated.
Database Reads
author_email
– Applied to the comment author’s email address retrieved from the database by thecomment_author_email
function. See alsoget_comment_author_email
.comment_author
– Applied to the comment author’s name retrieved from the database by thecomment_author
function. See alsoget_comment_author
.comment_author_rss
– Applied to the comment author’s name prior to including in an RSS feed.comment_email
– Applied to the comment author’s email address retrieved from the database by thecomment_author_email_link
function.comment_url
– Applied to the comment author’s URL retrieved from the database by thecomment_author_url
function (see alsoget_comment_author_url
).get_comment_author
– Applied to the comment author’s name retrieved from the database byget_comment_author
, which is also called bycomment_author
. See alsocomment_author
.get_comment_author_email
– Applied to the comment author’s email address retrieved from the database byget_comment_author_email
, which is also called bycomment_author_email
. See alsoauthor_email
.get_comment_author_IP
– Applied to the comment author’s IP address retrieved from the database by theget_comment_author_IP
function, which is also called bycomment_author_IP
.get_comment_author_url
– Applied to the comment author’s URL retrieved from the database by theget_comment_author_url
function, which is also called bycomment_author_url
. See alsocomment_url
.login_errors
– Applied to the login error message printed on the login screen.login_headertitle
– Applied to the title for the login header URL (Powered by WordPress by default) printed on the login screen.login_headerurl
– Applied to the login header URL (points to wordpress.org by default) printed on the login screen.login_message
– Applied to the login message printed on the login screen.role_has_cap
– Applied to a role’s capabilities list in theWP_Role->has_cap
function. Filter function arguments are the capabilities list to be filtered, the capability being questioned, and the role’s name.sanitize_user
– Applied to a user name by thesanitize_user
function. Filter function arguments: user name (after some cleaning up), raw user name, strict (true or false to use strict ASCII or not).the_author
– Applied to a post author’s displayed name by theget_the_author
function, which is also called by thethe_author
function.the_author_email
– Applied to a post author’s email address by thethe_author_email
function.user_search_columns
– Applied to the list of columns in thewp_users
table to include in theWHERE
clause insideWP_User_Query
.
Database Writes
pre_comment_author_email
– Applied to a comment author’s email address prior to saving the comment in the database.pre_comment_author_name
– Applied to a comment author’s user name prior to saving the comment in the database.pre_comment_author_url
– Applied to a comment author’s URL prior to saving the comment in the database.pre_comment_user_agent
– Applied to the comment author’s user agent prior to saving the comment in the database.pre_comment_user_ip
– Applied to the comment author’s IP address prior to saving the comment in the database.pre_user_id
– Applied to the comment author’s user ID prior to saving the comment in the database.pre_user_description
– Applied to the user’s description prior to saving in the database.pre_user_display_name
– Applied to the user’s displayed name prior to saving in the database.pre_user_email
– Applied to the user’s email address prior to saving in the database.pre_user_first_name
– Applied to the user’s first name prior to saving in the database.pre_user_last_name
– Applied to the user’s last name prior to saving in the database.pre_user_login
– Applied to the user’s login name prior to saving in the database.pre_user_nicename
– Applied to the user’s “nice name” prior to saving in the database.pre_user_nickname
– Applied to the user’s nickname prior to saving in the database.pre_user_url
– Applied to the user’s URL prior to saving in the database.registration_errors
– Applied to the list of registration errors generated while registering a user for a new account.user_registration_email
– Applied to the user’s email address read from the registration page, prior to trying to register the person as a new user.validate_username
– Applied to the validation result on a new user name. Filter function arguments: valid (true/false), user name being validated.
Blogroll Filters
These hooks are for filtering content related to blogroll links.
get_bookmarks
– Applied to link/blogroll database query results by theget_bookmarks
function. Filter function arguments: database query results list,get_bookmarks
arguments list.link_category
– Applied to the link category by the get_links_list andwp_list_bookmarks
functions (as of WordPress 2.2).link_description
– Applied to the link description by the get_links and wp_list_bookmarks functions (as of WordPress 2.2).link_rating
– Applied to the link rating number by theget_linkrating
function.link_title
– Applied to the link title by the get_links andwp_list_bookmarks
functions (as of WordPress 2.2)pre_link_description
– Applied to the link description prior to saving in the database.pre_link_image
– Applied to the link image prior to saving in the database.pre_link_name
– Applied to the link name prior to saving in the database.pre_link_notes
– Applied to the link notes prior to saving in the database.pre_link_rel
– Applied to the link relation information prior to saving in the database.pre_link_rss
– Applied to the link RSS URL prior to saving in the database.pre_link_target
– Applied to the link target information prior to saving in the database.pre_link_url
– Applied to the link URL prior to saving in the database.
Blog Information and Option Filters
all_options
– Applied to the option list retrieved from the database by theget_alloptions
function.all_plugins
– Applied to the list of plugins retrieved for display in the plugins list table.bloginfo
– Applied to the blog option information retrieved from the database by thebloginfo
function, after first retrieving the information with theget_bloginfo
function. A second argument$show
gives the name of thebloginfo
option that was requested. Note thatbloginfo("url")
,bloginfo("directory")
andbloginfo("home")
do not use this filtering function (seebloginfo_url
).bloginfo_rss
– Applied to the blog option information by function get_bloginfo_rss (which is also called from bloginfo_rss), after first retrieving the information with the get_bloginfo function, stripping out HTML tags, and converting characters appropriately. A second argument $show gives the name of the bloginfo option that was requested.bloginfo_url
– Applied to the the output ofbloginfo("url")
,bloginfo("directory")
andbloginfo("home")
before returning the information.loginout
– Applied to the HTML link for logging in and out (generally placed in the sidebar) generated by the wp_loginout function.lostpassword_url
– Applied to the URL that allows users to reset their passwords.option_(option name)
– Applied to the option value retrieved from the database by the get_option function, after unserializing (which decodes array-based options). To use this filter, you will need to add filters for specific options names, such as “option_foo” to filter the output of get_option(“foo”).pre_get_space_used
– Applied to theget_space_used()
function to provide an alternative way of displaying storage space used. Returning false from this filter will revert to default display behavior (usedwp_upload_dir()
directory space in megabytes).pre_option_(option name)
– Applied to the option value retrieved from the database by theget_alloptions
function, after unserializing (which decodes array-based options). To use this filter, you will need to add filters for specific options names, such as “pre_option_foo
” to filter the option “foo”.pre_update_option_(option name)
– Applied the option value before being saving to the database to allow overriding the value to be stored. To use this filter, you will need to add filters for specific options names, such as “pre_update_option_foo
” to filter the option “foo”.register
– Applied to the sidebar link created for the user to register (if allowed) or visit the admin panels (if already logged in) by thewp_register
function.upload_dir
– Applied to the directory to be used for uploads calculated by thewp_upload_dir
function. Filter function argument is an array with components “dir” (the upload directory path), “url” (the URL of the upload directory), and “error” (which you can set to true if you want to generate an error).upload_mimes
– Allows a filter function to return a list of MIME types for uploads, if there is no MIME list input to thewp_check_filetype
function. Filter function argument is an associated list of MIME types whose component names are file extensions (separated by vertical bars) and values are the corresponding MIME types.
General Text Filters
attribute_escape
– Applied to post text and other content by the attribute_escape function, which is called in many places in WordPress to change certain characters into HTML attributes before sending to the browser.js_escape
– Applied to JavaScript code before sending to the browser in the js_escape function.sanitize_key
– Applied to key before using it for your settings, field, or other needs, generated bysanitize_key
function
Administrative Filters
These hooks let you filter content related to the WordPress dashboard, including content editing screens.
admin_user_info_links
– Applied to the user profile and info links in the WordPress admin quick menu.autosave_interval
– Applied to the interval for auto-saving posts.bulk_actions
– Applied to an array of bulk items in admin bulk action drop-downs.bulk_post_updated_messages
– Applied to an array of bulk action updated messages.cat_rows
– Applied to the category rows HTML generated for managing categories in the admin menus.comment_edit_pre
– Applied to comment content prior to display in the editing screen.- comment_edit_redirect – Applied to the redirect location after someone edits a comment in the admin
menus
. Filter function arguments: redirect location, comment ID. comment_moderation_subject
– Applied to the mail subject before sending email notifying the administrator of the need to moderate a new comment. Filter function arguments: mail subject, comment ID. Note that this happens inside the defaultwp_notify_moderator
function, which is a “pluggable” function, meaning that plugins can override it; see Plugin API).comment_moderation_text
– Applied to the body of the mail message before sending email notifying the administrator of the need to moderate a new comment. Filter function arguments: mail body text, comment ID. Note that this happens inside the defaultwp_notify_moderator
function, which is a “pluggable” function, meaning that plugins can override it; see Plugin API).comment_notification_headers
– Applied to the mail headers before sending email notifying the post author of a new comment. Filter function arguments: mail header text, comment ID. Note that this happens inside the defaultwp_notify_postauthor
function, which is a “pluggable” function, meaning that plugins can override it; see Plugin API).comment_notification_subject
– Applied to the mail subject before sending email notifying the post author of a new comment. Filter function arguments: mail subject, comment ID. Note that this happens inside the defaultwp_notify_postauthor
function, which is a “pluggable” function, meaning that plugins can override it; see Plugin API).comment_notification_text
– Applied to the body of the mail message before sending email notifying the post author of a new comment. Filter function arguments: mail body text, comment ID. Note that this happens inside the defaultwp_notify_postauthor
function, which is a “pluggable” function, meaning that plugins can override it; see Plugin API).comment_row_actions
– Applied to the list of action links under each comment row (like Reply, Quick Edit, Edit).cron_request
– Allows filtering of the URL, key and arguments passed towp_remote_post()
inspawn_cron()
.cron_schedules
– Applied to an empty array to allow a plugin to generate cron schedules in thewp_get_schedules
function.custom_menu_order
– Used to activate the ‘menu_order
‘ filter.default_content
– Applied to the default post content prior to opening the editor for a new post.default_excerpt
– Applied to the default post excerpt prior to opening the editor for a new post.default_title
– Applied to the default post title prior to opening the editor for a new post.editable_slug
– Applied to the post, page, tag or category slug by theget_sample_permalink
function.format_to_edit
– Applied to post content, excerpt, title, and password by theformat_to_edit
function, which is called by the admin menus to set up a post for editing. Also applied to when editing comments in the admin menus.format_to_post
– Applied to post content by theformat_to_post
function, which is not used in WordPress by default.manage_edit-${post_type}_columns
– Applied to the list of columns to print on the manage posts screen for a custom post type. Filter function argument/return value is an associative array where the element key is the name of the column, and the value is the header text for that column. See also actionmanage_${post_type}_posts_custom_column
, which puts the column information into the edit screen.manage_link-manager_columns
– Wasmanage_link_columns
until WordPress 2.7. applied to the list of columns to print on the blogroll management screen. Filter function argument/return value is an associative list where the element key is the name of the column, and the value is the header text for that column. See also actionmanage_link_custom_column
, which puts the column information into the edit screen.- manage_posts_columns – Applied to the list of columns to print on the manage posts screen. Filter function argument/return value is an associative array where the element key is the name of the column, and the value is the header text for that column. See also action
manage_posts_custom_column
, which puts the column information into the edit screen. (see Scompt’s tutorial for examples and use.) manage_pages_columns
– Applied to the list of columns to print on the manage pages screen. Filter function argument/return value is an associative array where the element key is the name of the column, and the value is the header text for that column. See also actionmanage_pages_custom_column
, which puts the column information into the edit screen.manage_users_columns
manage_users_custom_column
manage_users_sortable_columns
media_row_actions
– Applied to the list of action links under each file in the Media Library (like View, Edit).menu_order
– Applied to the array for the admin menu order. Must be activated with the ‘custom_menu_order
‘ filter before.nonce_life
– Applied to the lifespan of a nonce to generate or verify the nonce. Can be used to generate nonces which expire earlier. The value returned by the filter should be in seconds.nonce_user_logged_out
– Applied to the current user ID used to generate or verify a nonce when the user is logged out.plugin_row_meta
– Add additional links below each plugin on the plugins page.postmeta_form_limit
– Applied to the number of post-meta information items shown on the post edit screen.post_row_actions
– Applied to the list of action links (like Quick Edit, Edit, View, Preview) under each post in the Posts > All Posts section.post_updated_messages
– Applied to the array storing user-visible administrative messages when working with posts, pages and custom post types. This filter is used to change the text of said messages, not to trigger them. See “customizing the messages” in theregister_post_type
documentation.pre_upload_error
– Applied to allow a plugin to create an XMLRPC error for uploading files.preview_page_link
– Applied to the link on the page editing screen that shows the page preview at the bottom of the screen.preview_post_link
– Applied to the link on the post editing screen that shows the post preview at the bottom of the screen.richedit_pre
– Applied to post content by thewp_richedit_pre
function, before displaying in the rich text editor.schedule_event
– Applied to each recurring and single event as it is added to the cron schedule.set-screen-option
– Filter a screen option value before it is set.show_password_fields
– Applied to the true/false variable that controls whether the user is presented with the opportunity to change their password on the user profile screen (true means to show password changing fields; false means don’t).terms_to_edit
– Applied to the CSV of terms (for each taxonomy) that is used to show which terms are attached to the post.the_editor
– Applied to the HTML DIV created to house the rich text editor, prior to printing it on the screen. Filter function argument/return value is a string.user_can_richedit
– Applied to the calculation of whether the user’s browser has rich editing capabilities, and whether the user wants to use the rich editor, in theuser_can_richedit
function. Filter function argument and return value is true/false if the current user can/cannot use the rich editor.user_has_cap
– Applied to a user’s capabilities list in theWP_User->has_cap
function (which is called by thecurrent_user_can
function). Filter function arguments are the capabilities list to be filtered, the capability being questioned, and the argument list (which has things such as the post ID if the capability is to edit posts, etc.)wp_handle_upload_prefilter
– Applied to the upload information when uploading a file. Filter function argument: array which represents a single element of$_FILES
.wp_handle_upload
– Applied to the upload information when uploading a file. Filter function argument: array with elements “file” (file name), “url”, “type”.wp_revisions_to_keep
– Alters how many revisions are kept for a given post. Filter function arguments: number representing desired revisions saved (default is unlimited revisions), the post object.wp_terms_checklist_args
– Applied to arguments of thewp_terms_checklist()
function. Filter function argument: array of checklist arguments, post ID.wp_upload_tabs
– Applied to the list of custom tabs to display on the upload management admin screen. Use actionupload_files_(tab)
to display a page for your custom tab (see Plugin API/Action Reference).media_upload_tabs
– Applied to the list of custom tabs to display on the upload management admin screen. Use actionupload_files_(tab)
to display a page for your custom tab (see Plugin API/Action Reference).plugin_action_links_
(plugin file name) – Applied to the list of links to display on the plugins page (beside the activate/deactivate links).views_edit-post
– Applied to the list posts eg All (30) | Published (22) | Draft (5) | Pending (2) | Trash (1)
Rich Text Editor Filters
Using these hooks, you can modify the configuration of TinyMCE, the rich text editor.
mce_spellchecker_languages
– Applied to the language selection available in the spell checker.mce_buttons
,mce_buttons_2
,mce_buttons_3
,mce_buttons_4
– Applied to the rows of buttons for the rich editor toolbar (each is an array of button names).mce_css
– Applied to the CSS file URL for the rich text editor.mce_external_plugins
– Applied to the array of external plugins to be loaded by the rich text editor.mce_external_languages
– Applied to the array of language files loaded by external plugins, allowing them to use the standard translation method (see tinymce/langs/wp-langs.php for reference).tiny_mce_before_init
– Applied to the whole init array for the editor.
Template Filters
The filter hooks in this section allow you to work with themes, templates, and style files.
locale_stylesheet_uri
– Applied to the locale-specific stylesheet URI returned by theget_locale_stylesheet_uri
function. Filter function arguments: URI, stylesheet directory URI.stylesheet
– Applied to the stylesheet returned by theget_stylesheet
function.stylesheet_directory
– Applied to the stylesheet directory returned by theget_stylesheet_directory
function. Filter function arguments: stylesheet directory, stylesheet.stylesheet_directory_uri
– Applied to the stylesheet directory URI returned by theget_stylesheet_directory_uri
function. Filter function arguments: stylesheet directory URI, stylesheet.stylesheet_uri
– Applied to the stylesheet URI returned by theget_stylesheet_uri
function. Filter function arguments: stylesheet URI, stylesheet.template
– Applied to the template returned by the get_template function.template_directory
– Applied to the template directory returned by theget_template_directory
function. Filter function arguments: template directory, template.template_directory_uri
– Applied to the template directory URI returned by theget_template_directory_uri
function. Filter function arguments: template directory URI, template.theme_root
– Applied to the theme root directory (normally wp-content/themes) returned by the get_theme_root function.theme_root_uri
– Applied to the theme root directory URI returned by theget_theme_root_uri
function. Filter function arguments: URI, site URL. You can also replace individual template files from your theme, by using the following filter hooks. See also thetemplate_redirect
action hook. Each of these filters takes as input the path to the corresponding template file in the current theme. A plugin can modify the file to be used by returning a new path to a template file.404_template
archive_template
– You can use this for example to enforce a specific template for a custom post type archive. This way you can keep all the code in a plugin.attachment_template
author_template
category_template
comments_popup_template
comments_template
– The “comments_template
” filter can be used to load a custom template form a plugin which replace the themes default comment template.date_template
home_template
page_template
paged_template
search_template
single_template
– You can use this for example to enforce a specific template for a custom post type. This way you can keep all the code in a plugin.shortcut_link
– Applied to the “Press This” bookmarklet link.- template_include
wp_nav_menu_args
– Applied to the arguments of thewp_nav_menu
function.wp_nav_menu_items
– Filter the HTML list content for navigation menus.
Registration & Login Filters
authenticate
– Allows basic authentication to be performed on login based on username and password.registration_errors
– Applied to the list of registration errors generated while registering a user for a new account.user_registration_email
– Applied to the user’s email address read from the registration page, prior to trying to register the person as a new user.validate_username
– Applied to the validation result on a new user name. Filter function arguments: valid (true/false), user name being validated.wp_authenticate_user
– Applied when a user attempted to log in, after WordPress validates username and password, but before validation errors are checked.
Redirect/Rewrite Filters – Advanced
These advanced filters relate to WordPress’s handling of rewrite rules.
allowed_redirect_hosts
– Applied to the list of host names deemed safe for redirection. wp-login.php uses this to defend against a dangerous ‘redirect_to
‘ request parameterauthor_rewrite_rules
– Applied to the author-related rewrite rules after they are generated.category_rewrite_rules
– Applied to the category-related rewrite rules after they are generated.comments_rewrite_rules
– Applied to the comment-related rewrite rules after they are generated.date_rewrite_rules
– Applied to the date-related rewrite rules after they are generated.mod_rewrite_rules
– Applied to the list of rewrite rules given to the user to put into their .htaccess file when they change their permalink structure. (Note: replaces deprecated filter rewrite_rules.)page_rewrite_rules
– Applied to the page-related rewrite rules after they are generated.post_rewrite_rules
– Applied to the post-related rewrite rules after they are generated.redirect_canonical
– Can be used to cancel a “canonical” URL redirect. Accepts 2 parameters:$redirect_url
,$requested_url
. To cancel the redirect returnFALSE
, to allow the redirect return$redirect_url
.rewrite_rules_array
– Applied to the entire rewrite rules array after it is generated.root_rewrite_rules
– Applied to the root-level rewrite rules after they are generated.search_rewrite_rules
– Applied to the search-related rewrite rules after they are generated.wp_redirect
– Applied to a redirect URL by the defaultwp_redirect
function. Filter function arguments: URL, HTTP status code. Note thatwp_redirect
is also a “pluggable” function, meaning that plugins can override it; see Plugin API).wp_redirect_status
– Applied to the HTTP status code when redirecting by the defaultwp_redirect
function. Filter function arguments: HTTP status code, URL. Note thatwp_redirect
is also a “pluggable” function, meaning that plugins can override it; see Plugin API).
WP_Query Filters
These are filters run by the WP_Query
object in the course of building and executing a query to retrieve posts.
found_posts
– Applied to the list of posts, just after querying from the database.found_posts_query
– After the list of posts to display is queried from the database, WordPress selects rows in the query results. This filter allows you to do something other thanSELECT FOUND_ROWS()
at that step.post_limits
– Applied to the LIMIT clause of the query that returns the post array.posts_clauses
– Applied to the entire SQL query, divided into a keyed array for each clause type, that returns the post array. Can be easier to work with thanposts_request
.posts_distinct
– Allows a plugin to add aDISTINCTROW
clause to the query that returns the post array.posts_fields
– Applied to the field list for the query that returns the post array.posts_groupby
– Applied to the GROUP BY clause of the query that returns the post array (normally empty).posts_join
– Applied to theJOIN
clause of the query that returns the post array. This is typically used to add a table to theJOIN
, in combination with theposts_where
filter.posts_join_paged
– Applied to theJOIN
clause of the query that returns the post array, after the paging is calculated (though paging does not affect theJOIN
, so this is actually equivalent toposts_join
).- posts_orderby – Applied to the
ORDER BY
clause of the query that returns the post array. posts_request
– Applied to the entire SQL query that returns the post array, just prior to running the query.posts_results
– Allows you to manipulate the resulting array returned from the query.posts_search
– Applied to the search SQL that is used in theWHERE
clause ofWP_Query
.posts_where
– Applied to theWHERE
clause of the query that returns the post array.posts_where_paged
– Applied to theWHERE
clause of the query that returns the post array, after the paging is calculated (though paging does not affect theWHERE
, so this is actually equivalent toposts_where
).the_posts
– Applied to the list of posts queried from the database after minimal processing for permissions and draft status on single-post pages.
Media Filters
These media filter hooks enabled you to integrate different types of media.
editor_max_image_size
image_downsize
get_image_tag_class
get_image_tag
image_resize_dimensions
intermediate_image_sizes
icon_dir
wp_get_attachment_image_attributes
img_caption_shortcode
post_gallery
use_default_gallery_style
gallery_style
(adjacent)_image_link
embed_defaults
load_default_embeds
embed_googlevideo
upload_size_limit
wp_image_editors
plupload_default_settings
plupload_default_params
image_size_names_choose
wp_prepare_attachment_for_js
media_upload_tabs
disable_captions
media_view_settings
media_view_strings
wp_handle_upload_prefilter
Advanced WordPress Filters
The advanced filter hooks in this section related to internationalization, miscellaneous queries, and other fundamental WordPress functions.
create_user_query
– Applied to the query used to save a new user’s information to the database, just prior to running the query.get_editable_authors
– Applied to the list of post authors that the current user is authorized to edit in theget_editable_authors
function.get_next_post_join
– Infunction
get_next_post (which finds the post after the currently-displayed post), applied to theSQL JOIN
clause (which normally joins to the category table if user is viewing a category archive). Filter function arguments:JOIN
clause, stay in same category (true/false), list of excluded categories.get_next_post_sort
– In function get_next_post (which finds the post after the currently-displayed post), applied to theSQL ORDER BY
clause (which normally orders by post date in ascending order with a limit of 1 post). Filter function arguments:ORDER BY
clause.get_next_post_where
– In functionget_next_post
(which finds the post after the currently-displayed post), applied to theSQL WHERE
clause (which normally looks for the next dated published post). Filter function arguments:WHERE
clause, stay in same category (true/false), list of excluded categories.get_previous_post_join
– In function get_previous_post (which finds the post before the currently-displayed post), applied to theSQL JOIN
clause (which normally joins to the category table if user is viewing a category archive). Filter function arguments: join clause, stay in same category (true/false), list of excluded categories.get_previous_post_sort
– In function get_previous_post (which finds the post before the currently-displayed post), applied to theSQL ORDER BY
clause (which normally orders by post date in descending order with a limit of 1 post). Filter function arguments:ORDER BY
clause.get_previous_post_where
– In functionget_previous_post
(which finds the post before the currently-displayed post), applied to theSQL WHERE
clause (which normally looks for the previous dated published post). Filter function arguments:WHERE
clause, stay in same category (true/false), list of excluded categories.gettext
– Applied to the translated text by thetranslation()
function (which is called by functions like the__()
and_e()
internationalization functions ). Filter function arguments: translated text, untranslated text and the text domain. Gets applied even if internationalization is not in effect or if the text domain has not been loaded.override_load_textdomain
get_meta_sql
– In functionWP_Meta_Query::get_sql
(which generates SQL clauses to be appended to a main query for advanced meta queries.), applied to theSQL JOIN
andWHERE
clause generated by the advanced meta query. Filter function arguments:array( compact( 'join', 'where' )
,$this->queries
,$type
,$primary_table
,$primary_id_column
,$context
)get_others_drafts
– Applied to the query that selects the other users’ drafts for display in the admin menus.get_users_drafts
– Applied to the query that selects the users’ drafts for display in the admin menus.locale
– Applied to the locale by theget_locale
function.query
– Applied to all queries (at least all queries run after plugins are loaded).query_string
– Deprecated – usequery_vars
or request instead.query_vars
– Applied to the list of public WordPress query variables before the SQL query is formed. Useful for removing extra permalink information the plugin has dealt with in some other manner.request
– Likequery_vars
, but applied after “extra” and private query variables have been added.excerpt_length
– Defines the length of a single-post excerpt.excerpt_more
– Defines the more string at the end of the excerpt.post_edit_form_tag
– Allows you to append code to the form tag in the default post/page editor.update_user_query
– Applied to the update query used to update user information, prior to running the query.uploading_iframe_src
(removed since WP 2.5) – Applied to the HTML src tag for the uploading iframe on the post and page editing screens.xmlrpc_methods
– Applied to list of defined XMLRPC methods for the XMLRPC server.wp_mail_from
– Applied before any mail is sent by thewp_mail
function. Supplied value is the calculated from address which is wordpress at the current hostname (set by$_SERVER['SERVER_NAME']
). The filter should return an email address or name/email combo in the form “user@example.com” or “Name <user@example.com>” (without the quotes!).wp_mail_from_name
– Applied before any mail is sent by thewp_mail
function. The filter should return a name string to be used as the email from name.update_(meta_type)_metadata
– Applied before a metadata gets updated. For example if a user metadata gets updated the hook would be ‘update_user_metadata
‘
Widgets
These filter hooks let you work with the widgets built into WordPress core.
dynamic_sidebar_params
– Applied to the arguments passed to thewidgets_init
function in the WordPress widgets.widget_archives_dropdown_args
– Applied to the arguments passed to thewp_get_archives()
function in the WordPress Archives widget.widget_categories_args
– Applied to the arguments passed to thewp_list_categories()
function in the WordPress Categories widget.widget_links_args
– Applied to the arguments passed to thewp_list_bookmarks()
function in the WordPress Links widget.widget_nav_menu_args
– Applied to the arguments passed to thewp_nav_menu()
function in the WordPress Custom Menu widget.widget_pages_args
– Applied to the arguments passed to thewp_list_pages()
function in the WordPress Pages widget.widget_tag_cloud_args
– Applied to the arguments passed to thewp_tag_cloud()
function in the WordPress Pages widget.widget_text
– Applied to the widget text of the WordPress Text widget. May also apply to some third party widgets as well.widget_title
– Applied to the widget title of any user editable WordPress Widget. May also apply to some third party widgets as well.
Conclusion
Filters are a fundamental concept in WordPress development, so understanding how they work and how to use them is essential if you’re interested in developing your own plugins and themes.
The Filter cheat sheet above provides an overview of how to code filters and develop with them, as well as a handy filter reference should you need to quickly find the right filter hook while coding. Be sure to bookmark it as a reference for your future WordPress development projects!
If you have any questions or additions for this cheat sheet, let us know in the comments below.
Leave a Reply