This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
“`html
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 filtering 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.
Example 1: Basic Hook Usage
This example demonstrates the basic use of the post_link_category filter.
$cats_0 = apply_filters( 'post_link_category', $cats_0, $cats, $post ); if ( !empty( $cats_0 ) ) { // everything has led up to this point... }
Example 2: Adding a Hook Callback
The following example adds a callback to the post_link_category filter.
// define the post_link_category callback function weplugins_filter_post_link_category( $cats_0, $cats, $post ) { // make filter magic happen here... return $cats_0; }; // add the filter add_filter( 'post_link_category', 'weplugins_filter_post_link_category', 10, 3 );
Example 3: Removing a Hook Callback
To remove a callback from the post_link_category filter, use the example below.
// remove the filter remove_filter( 'post_link_category', 'weplugins_filter_post_link_category', 10, 3 );
Contact Us
If you need any customization, feel free to contact us.
“`
Explore the latest in WordPress
Trying to stay on top of it all? Get the best tools, resources and inspiration sent to your inbox every Wednesday.