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.
post_link filter
Filters the permalink for a post.
apply_filters( 'post_link', string $permalink, WP_Post $post, bool $leavename )
Description
This hook is used to filter the permalink for a post. It applies only to posts with the default post_type of ‘post’, and can’t be applied to custom posts.
The post_link filter is applied to the permalink URL for a post before returning the processed URL by the function get_permalink().
This filter only applies to posts with the post_type of ‘post’. For a filter that applies to custom post types, look at post_type_link.
Parameters
- $permalink : (string) The post’s permalink.
- $post : (WP_Post) The post in question.
- $leavename : (bool) Whether to keep the post name.
Live Examples
Example 1: Running the Hook
To run the hook, copy the example below.
$permalink = apply_filters( 'post_link', $permalink, $post, $leavename ); if ( !empty( $permalink ) ) { // everything has led up to this point... }
Example 2: Adding a Hook Callback
The following example shows how to add a hook callback.
// define the post_link callback function weplugins_filter_post_link( $permalink, $post, $leavename ) { // make filter magic happen here... return $permalink; }; // add the filter add_filter( 'post_link', 'weplugins_filter_post_link', 10, 3 );
Example 3: Removing a Hook Callback
To remove a hook callback, use the example below.
// remove the filter remove_filter( 'post_link', 'weplugins_filter_post_link', 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.