Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get post permalink


Retrieves the permalink for a post with a custom post type.

This function is very similar to get_permalink().


<?php get_post_permalink$id$leavename$sample ); ?>

Default Usage

<?php get_post_permalink(); ?>


(integer) (optional) Post ID. This parameter is not required when used within The Loop.
Default: 0
(boolean) (optional) Whether to keep the post name. When set to true, a structural link will be returned, rather than the actual URI. Example: http://www.example.com/%postname% instead of http://www.example.com/my-post.
Default: false
(boolean) (optional) Is it a sample permalink? If the post type has extra permastructure and the post's status is draft or pending, a link with the post ID as a GET parameter (e.g. http://example.com/?post=53) will be returned instead of the usual permalink, unless the link is a sample ($sample is true).
Default: false

Return Values

The permalink for the post, or a WP_Error object if the post does not exist.


See get_permalink() for examples.



Source Code

get_post_permalink() is located in wp-includes/link-template.php.


get_permalink(), the_permalink(), post_permalink(), permalink_anchor(), permalink_single_rss()

See also index of Function Reference and index of Template Tags.
This article is marked as in need of editing. You can help Codex by editing it.