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

Filters the permalink for a post of a custom post type.


Parameters Parameters

$post_link

(string) The post's permalink.

$post

(WP_Post) The post in question.

$leavename

(bool) Whether to keep the post name.

$sample

(bool) Is it a sample permalink.


Top ↑

More Information More Information

post_type_link is a filter applied to the permalink URL for a post or custom post type prior to being returned by the function get_post_permalink() .


Top ↑

Source Source

File: wp-includes/link-template.php

View on Trac



Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by stevenlinx

    Example migrated from Codex:

    Append the query string for the custom post type ‘my_custom_post_type’ permalink URLs ( uses add_query_arg() and get_post_type() ):

    function append_query_string( $url, $post ) {
        if ( 'my_custom_post_type' == get_post_type( $post ) ) {
            return add_query_arg( $_GET, $url );
        }
        return $url;
    }
    add_filter( 'post_type_link', 'append_query_string', 10, 2 );
    

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