WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Plugin API/Filter Reference/post type link

Description

post_type_link is a filter applied to the permalink URL for a post or custom post type prior to printing by the function get_post_permalink.

Parameters

$url
(string) (required) The post URL
Default: None
$post
(object) (optional) The post object
Default: None
$leavename
(bool) (optional) Whether to keep the post name
Default: false
$sample
(bool) (optional) Is it a sample permalink?
Default: false

Examples

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 );

Change Log

Source Files

This filter is applied by:

Related

This article is marked as in need of editing. You can help Codex by editing it.