Filter hook 'post_link_category'

in WP Core File wp-includes/link-template.php at line 244

View Source

post_link_category

Filter Hook
Description
Filters the category that gets used in the %category% permalink token.

Hook Information

File Location wp-includes/link-template.php View on GitHub
Hook Type Filter
Line Number 244

Hook Parameters

Type Name Description
WP_Term $cat The category to use in the permalink.
array $cats Array of all categories (WP_Term objects) associated with the post.
WP_Post $post The post in question.

Usage Examples

Basic Usage
<?php
// Hook into post_link_category
add_filter('post_link_category', 'my_custom_filter', 10, 3);

function my_custom_filter($cat, $cats, $post) {
    // Your custom filtering logic here
    return $cat;
}

Source Code Context

wp-includes/link-template.php:244 - How this hook is used in WordPress core
<?php
 239  				 *
 240  				 * @param WP_Term  $cat  The category to use in the permalink.
 241  				 * @param array    $cats Array of all categories (WP_Term objects) associated with the post.
 242  				 * @param WP_Post  $post The post in question.
 243  				 */
 244  				$category_object = apply_filters( 'post_link_category', $cats[0], $cats, $post );
 245  
 246  				$category_object = get_term( $category_object, 'category' );
 247  				$category        = $category_object->slug;
 248  				if ( $category_object->parent ) {
 249  					$category = get_category_parents( $category_object->parent, false, '/', true ) . $category;

PHP Documentation

<?php
/**
				 * Filters the category that gets used in the %category% permalink token.
				 *
				 * @since 3.5.0
				 *
				 * @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.
				 */
Quick Info
  • Hook Type: Filter
  • Parameters: 3
  • File: wp-includes/link-template.php
Related Hooks

Related hooks will be displayed here in future updates.