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
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
false i will already have the post name in the URL. So again , What makes me turn it to
get_permalink(). It's an optional value to decide whether to keep the post's name or not.
Structure Tagfor the post's name.
$leavevalueis equal to
trueunless 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.