As already known that the function the_permalink
echos out the URL for current post in the loop, while the function get_permalink
returns the permalink for a specific post using $post_id
, but get_permalink
has the $leavename
that allows return the URL structure of a post to finally (for example) get a URL that looks like this http://localhost/%postname%/
. So, When do i may need such output?
Please notice the output:
<?php
$x= get_permalink($post_id, true);
echo $x;
//output
//http://localhost/%postname%/
?>
If i turned the $leavename
to false
i will already have the post name in the URL. So again , What makes me turn it to true
get_permalink()
. It's an optional value to decide whether to keep the post's name or not.Structure Tag
for the post's name.$leavevalue
is equal to%postname%
true
unless for developing purposes. As @Milo mentioned, the URL preview mechanism (or some plugins) use that function to update the slug based on the original post's name. You don't need it for theme development.