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.
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.
Return
String/false. The permalink URL or false if post does not exist.
Usage
get_the_permalink( $post, $leavename );
- $post(int/WP_Post)
- Post ID or post object, which link we want to retrieve.
Default: global $post - $leavename(true/false)
- 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
Examples
#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
Notes
- See: get_permalink()
Changelog
Since 3.9.0 | Introduced. |
Code of get_the_permalink() get the permalink WP 5.6
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...
- edit_post_link()
- get_delete_post_link()
- get_edit_post_link()
- get_post_field()
- get_post_status()
- get_post_time()
- get_the_content()
- get_the_date()
- get_the_excerpt()
- get_the_ID()