the_permalink() WordPress Function

The the_permalink() function is used to display the URL of the current post or page. This is useful when you want to share a post or page with others.

the_permalink( int|WP_Post $post ) #

Displays the permalink for the current post.


Parameters

$post

(int|WP_Post)(Optional) Post ID or post object. Default is the global $post.


Top ↑

More Information

This tag must be within The Loop, and is generally used to display the permalink for each post, when the posts are being displayed. Since this template tag is limited to displaying the permalink for the post that is being processed, you cannot use it to display the permalink to an arbitrary post on your weblog. Refer to get_permalink() if you want to get the permalink for a post, given its unique post id.


Top ↑

Source

File: wp-includes/link-template.php

function the_permalink( $post = 0 ) {
	/**
	 * Filters the display of the permalink for the current post.
	 *
	 * @since 1.5.0
	 * @since 4.4.0 Added the `$post` parameter.
	 *
	 * @param string      $permalink The permalink for the current post.
	 * @param int|WP_Post $post      Post ID, WP_Post object, or 0. Default 0.
	 */
	echo esc_url( apply_filters( 'the_permalink', get_permalink( $post ), $post ) );
}


Top ↑

Changelog

Changelog
VersionDescription
4.4.0Added the $post parameter.
1.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More