post_link_category

Filters the category that gets used in the %category% permalink token.

Description

apply_filters( 'post_link_category', (WP_Term) $cats_0, (array) $cats, (WP_Post) $post ); 

Parameters (3)

0. $cats_0 (WP_Term)
The category to use in the permalink.
1. $cats (array)
Array of all categories (WP_Term objects) associated with the post.
2. $post (WP_Post)
The post in question.

Usage

To run the hook, copy the example below.
  1. $cats_0 = apply_filters( 'post_link_category', $cats_0, $cats, $post ); 
  2.  
  3. if ( !empty( $cats_0 ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the post_link_category callback 
  2. function filter_post_link_category( $cats_0, $cats, $post ) { 
  3. // make filter magic happen here... 
  4. return $cats_0
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'post_link_category', 'filter_post_link_category', 10, 3 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'post_link_category', 'filter_post_link_category', 10, 3 ); 

Defined (1)

The filter is defined in the following location(s).

/wp-includes/link-template.php  
  1. $category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post );