Title: pre_post_link
Published: April 25, 2014
Last modified: August 20, 2026

---

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

## In this article

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

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

Filters the permalink structure for a post before token replacement occurs.

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

Only applies to posts with post_type of ‘post’.

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

 `$permalink`string

The site’s permalink structure.

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

The post in question.

`$leavename`bool

Whether to keep the post name.

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

    ```php
    $permalink = apply_filters( 'pre_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/7.1/src/wp-includes/link-template.php#L217)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/link-template.php#L217-L217)

## 󠀁[Related](https://developer.wordpress.org/reference/hooks/pre_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/pre_post_link/?output_format=md#changelog)󠁿

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

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

 1.   [Skip to note 2 content](https://developer.wordpress.org/reference/hooks/pre_post_link/?output_format=md#comment-content-7089)
 2.    [Noruzzaman](https://profiles.wordpress.org/noruzzaman/)  [  2 years ago  ](https://developer.wordpress.org/reference/hooks/pre_post_link/#comment-7089)
 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%2Fpre_post_link%2F%23comment-7089)
     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%2Fpre_post_link%2F%23comment-7089)
 4.  **Modifying Pre-Post Links in WordPress**
      we will learn how to modify the default
     permalink structure of your WordPress posts using the **pre_post_link filter**.
     We will write a function to customize the permalink and then add and remove this
     filter.
 5.  **Step 1: Add the Filter**
 6.      ```php
         function wpdocs_modify_pre_post_link_defaults( $permalink, $post ) {
             // Check if the post type is 'post'
             if ( 'post' === $post->post_type ) {
                 // Append '-custom' to the permalink
                 $permalink = str_replace( '%postname%', '%postname%-custom', $permalink );
             }
     
             return $permalink;
         }
     
         add_filter( 'pre_post_link', 'wpdocs_modify_pre_post_link_defaults', 10, 2 );
         ```
     
 7.  **Step 2: Remove the Filter**
 8.      ```php
         remove_filter( 'pre_post_link', 'wpdocs_modify_pre_post_link_defaults' );
         ```
     
 9.   [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fhooks%2Fpre_post_link%2F%3Freplytocom%3D7089%23feedback-editor-7089)

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