WordPress

get_permalink()

Introduction#

This function returns the full paralink of the current post or the designated post.

Syntax#

  • get_permalink( $post, $leavename )

Parameters#

Parameter Details
$post (int) (optional) Post ID or post object. Default is the the current post’s id.
$leavename (bool) (optional) Whether to keep post name or page name.
## Remarks#
For the parameter $leavename, it is false by default.
## Simple use of get_parmalink
Code
echo get_permalink();

Output

The link of the current page, for example: https://website.com/category/name-of-post/

Specifying the post to get the link

Code

echo get_permalink( 44 );

Output

The link of the post id:44, for example: https://website.com/category/name-of-post/

Get the link without the post’s name

Code

echo get_permalink( 44 , false );

Output

The link of the post id:44 without the name of the post, for example: https://website.com/category/%postname%/


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow