post_link_category
Filters the category that gets used in the %category% permalink token.
Usage
add_filter( 'post_link_category', 'wp_kama_post_link_category_filter', 10, 3 );
/**
* Function for `post_link_category` filter-hook.
*
* @param WP_Term $cat The category to use in the permalink.
* @param array $cats Array of all categories (WP_Term objects) associated with the post.
* @param WP_Post $post The post in question.
*
* @return WP_Term
*/
function wp_kama_post_link_category_filter( $cat, $cats, $post ){
// filter...
return $cat;
}
- $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.
Changelog
| Since 3.5.0 | Introduced. |
Where the hook is called
wp-includes/link-template.php 244
$category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post );