post_link_category filter
Filters the category that gets used in the %category% permalink token.
apply_filters( 'post_link_category', WP_Term $cat, array $cats, WP_Post $post )
Description
This hook is used for filter the category that’s used in the %category% permanent token.
This is also used by get_permalink() action which retrieves the full permalink for the current post or post ID.
Parameters
- $cat : (WP_Term) The category to use in the permalink.
- $cats : (array) Array of all categories (WP_Term objects) associated with the post.
- $post : (WP_Post) The post in question.
Live Example
To run the hook, copy the example below.
$cats_0 = apply_filters( 'post_link_category', $cats_0, $cats, $post ); if ( !empty( $cats_0 ) ) { // everything has led up to this point... }
The following example is for adding a hook callback.
// define the post_link_category callback function filter_post_link_category( $cats_0, $cats, $post ) { // make filter magic happen here... return $cats_0; }; // add the filter add_filter( 'post_link_category', 'filter_post_link_category', 10, 3 );
To remove a hook callback, use the example below.
// remove the filter remove_filter( 'post_link_category', 'filter_post_link_category', 10, 3 );