WordPress.org

Codex

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.

This filter only applies to posts with post_type of 'post'. For that filter which applies to custom post type look post_type_link

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=false ) {
	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