WordPress at a glance

get_the_permalink() WP 3.9.0

Gets, rather than displays, the URL of the post that is currently being processed in the Loop. Template tag.

get_the_permalink() is a copy of the get_permalink() function.


String/false. The permalink URL or false if post does not exist.

Works based on: get_permalink()
1 time = 0.002494s = very slow | 50000 times = 7.14s = fast | PHP 7.1.11, WP 4.9.8

No Hooks.


get_the_permalink( $post, $leavename );
Post ID or post object, which link we want to retrieve.
Default: global $post
Do not replace the name of the post in the link, i.e. do not replace the tag %postname% with the name of the post.
Default: false


#1 Example of use

Get a link to the current post in the loop:

<a href="<?php echo get_the_permalink(); ?>">Reed more...</a>

#2 Get the link to a specific post

$url = get_the_permalink( 23 ); // http://site.com/post-name/

#3 Second parameter: $leavename

The result depends on the permalink structure. Suppose that we have such a structure: %post_id%/%postname%.html, then:

$url = get_the_permalink( 23 );
echo get_the_permalink( 1, true );

// display: http://domain.com/1/%postname%.html


  • See: get_permalink()

Список изменений

С версии 3.9.0 Введена.

Code of get_the_permalink() WP 5.5.1

function get_the_permalink( $post = 0, $leavename = false ) {
	return get_permalink( $post, $leavename );

Related Functions

From tag: permalinks (clean friendly URL)

More from category: Posts, pages...

vladlu 100vlad.lu
Editors: kama 100
No comments
    Log In . Register