Title: post_link
Published: April 25, 2014
Last modified: February 24, 2026

---

# apply_filters( ‘post_link’, string $permalink, WP_Post $post, bool $leavename )

## In this article

 * [Description](https://developer.wordpress.org/reference/hooks/post_link/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/hooks/post_link/?output_format=md#parameters)
 * [More Information](https://developer.wordpress.org/reference/hooks/post_link/?output_format=md#more-information)
 * [Source](https://developer.wordpress.org/reference/hooks/post_link/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/hooks/post_link/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/hooks/post_link/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/hooks/post_link/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/hooks/post_link/?output_format=md#wp--skip-link--target)

Filters the permalink for a post.

## 󠀁[Description](https://developer.wordpress.org/reference/hooks/post_link/?output_format=md#description)󠁿

Only applies to posts with post_type of ‘post’.

## 󠀁[Parameters](https://developer.wordpress.org/reference/hooks/post_link/?output_format=md#parameters)󠁿

 `$permalink`string

The post’s permalink.

`$post`[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)

The post in question.

`$leavename`bool

Whether to keep the post name.

## 󠀁[More Information](https://developer.wordpress.org/reference/hooks/post_link/?output_format=md#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()](https://developer.wordpress.org/reference/functions/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](https://developer.wordpress.org/reference/hooks/post_type_link/).

## 󠀁[Source](https://developer.wordpress.org/reference/hooks/post_link/?output_format=md#source)󠁿

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

[View all references](https://developer.wordpress.org/reference/files/wp-includes/link-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/link-template.php#L308)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/link-template.php#L308-L308)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/post_link/?output_format=md#related)󠁿

| Used by | Description | 
| [get_permalink()](https://developer.wordpress.org/reference/functions/get_permalink/)`wp-includes/link-template.php` |

Retrieves the full permalink for the current post or post ID.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/hooks/post_link/?output_format=md#changelog)󠁿

| Version | Description | 
| [1.5.0](https://developer.wordpress.org/reference/since/1.5.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/hooks/post_link/?output_format=md#user-contributed-notes)󠁿

 1.   [Skip to note 4 content](https://developer.wordpress.org/reference/hooks/post_link/?output_format=md#comment-content-4486)
 2.    [Steven Lin](https://profiles.wordpress.org/stevenlinx/)  [  5 years ago  ](https://developer.wordpress.org/reference/hooks/post_link/#comment-4486)
 3.  [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_link%2F%23comment-4486)
     Vote results for this note: 1[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_link%2F%23comment-4486)
 4.  Example migrated from Codex:
 5.  Append the query string for posts to permalink URLs (uses [add_query_arg](https://developer.wordpress.org/reference/functions/add_query_arg/)):
 6.      ```php
         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 );
         ```
     
 7.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_link%2F%3Freplytocom%3D4486%23feedback-editor-4486)
 8.   [Skip to note 5 content](https://developer.wordpress.org/reference/hooks/post_link/?output_format=md#comment-content-3585)
 9.    [Anders Norén](https://profiles.wordpress.org/anlino/)  [  6 years ago  ](https://developer.wordpress.org/reference/hooks/post_link/#comment-3585)
 10. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_link%2F%23comment-3585)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_link%2F%23comment-3585)
 11. For other post types, use the following filters:
 12.  * _page_: [`page_link`](https://developer.wordpress.org/reference/hooks/page_link/)
      * _attachment_: [`attachment_link`](https://developer.wordpress.org/reference/hooks/attachment_link/)
      * Custom post types: [`post_type_link`](https://developer.wordpress.org/reference/hooks/post_type_link/)
 13.  * There is also [`term_link`](https://developer.wordpress.org/reference/hooks/term_link/)
        for archive pages, such as categories.
      * [nicohood](https://profiles.wordpress.org/nicohood/) [4 years ago](https://developer.wordpress.org/reference/hooks/post_link/#comment-5783)
 14.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_link%2F%3Freplytocom%3D3585%23feedback-editor-3585)
 15.  [Skip to note 6 content](https://developer.wordpress.org/reference/hooks/post_link/?output_format=md#comment-content-5829)
 16.   [jmfisherr](https://profiles.wordpress.org/jmfisherr/)  [  4 years ago  ](https://developer.wordpress.org/reference/hooks/post_link/#comment-5829)
 17. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_link%2F%23comment-5829)
     Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_link%2F%23comment-5829)
 18.     ```php
         /**
          * 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);
         ```
     
 19. Used to remove parent category slug from permalinks and maintain subcategories
     in URL
 20.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_link%2F%3Freplytocom%3D5829%23feedback-editor-5829)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpost_link%2F)
before being able to contribute a note or feedback.