apply_filters( 'post_link', string $permalink, WP_Post $post, bool $leavename )

Filters the permalink for a post.


Only applies to posts with post_type of ‘post’.

Top ↑


$permalink string
The post's permalink.
$post WP_Post
The post in question.
$leavename bool
Whether to keep the post name.

Top ↑

More Information

post_link is a filter applied to the permalink URL for a post prior to returning the processed url by the function get_permalink() .

This filter only applies to posts with post_type of ‘post’. For that filter which applies to custom post type look post_type_link.

Top ↑


File: wp-includes/link-template.php. View all references

return apply_filters( 'post_link', $permalink, $post, $leavename );

Top ↑


Version Description
1.5.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by Steven Lin

    Example migrated from Codex:

    Append the query string for posts to permalink URLs (uses add_query_arg):

    function append_query_string( $url, $post, $leavename=false ) {
    	if ( $post->post_type == 'post' ) {
    		$url = add_query_arg( 'foo', 'bar', $url );
    	return $url;
    add_filter( 'post_link', 'append_query_string', 10, 3 );
  2. Skip to note 3 content
    Contributed by jmfisherr
     * Filter to remove a particular slug from post urls
    function remove_slug_from_URL($permalink) {
    	$new_link = str_replace('/slug-to-remove', '', $permalink);
    	return $new_link;
    add_filter( 'post_link', 'remove_slug_from_URL', 10, 1);

    Used to remove parent category slug from permalinks and maintain subcategories in URL

You must log in before being able to contribute a note or feedback.