get_the_permalink()
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.
Uses: get_permalink()
1 time — 0.002494 sec (very slow) | 50000 times — 7.14 sec (fast) | PHP 7.1.11, WP 4.9.8
No Hooks.
Return
String|false
. The permalink URL. False if the 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. |
get_the_permalink() get the permalink code WP 6.7.2
function get_the_permalink( $post = 0, $leavename = false ) { return get_permalink( $post, $leavename ); }