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 link

Description

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

Parameters

$permalink
(string) (required) The post URL
Default: None
$post
(object) (required) The post object
Default: None
$leavename
(bool) (optional) Whether to keep the post name or page name. When set to true, a structural link will be returned, rather than the actual URI. Example: http://www.example.com/%postname% instead of http://www.example.com/my-post
Default: false

Examples

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

function append_query_string( $url, $post, $leavename ) {
	if ( $post->post_type == 'post' ) {
		$url = add_query_arg( 'foo', 'bar', $url );
	}
	return $url;
}
add_filter( 'post_link', 'append_query_string', 10, 3 );

Change Log

Source Files

This filter is applied by:

Related