Codex

Template Tags/get permalink

Contents

Description

Returns the permalink to a post for use in PHP. It does NOT display the permalink and can be used outside of The Loop.

Note the when used outside The Loop on a posts page (index, archive, etc.) without the ID parameter, it will return the URL of the last post in The Loop, not the permalink for the current page. See: http://core.trac.wordpress.org/ticket/9963

Usage

 <?php $permalink get_permalink$id ); ?> 

Parameters

$id
(integer) (optional) The numeric ID for a post.
Default: The current post ID, when used in The Loop.

Examples

Default Usage

The permalink for current post (used within The Loop). As the tag does not display the permalink, the example uses the PHP echo command.

Permalink for this post:<br />
<?php echo get_permalink(); ?>

Link to Specific Post

Returns the permalinks of two specific posts (post IDs 1 and 10) as hypertext links within an informational list. As above, tag uses the PHP echo command to display the permalink.

<ul>
<li>MyBlog info:
    <ul>
    <li><a href="<?php echo get_permalink(1); ?>">About MyBlog</a></li>
    <li><a href="<?php echo get_permalink(10); ?>">About the owner</a></li>
    </ul>
</li>
</ul>

Change Log

Since: 1.0.0

Source File

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

Related

get_permalink, the_permalink, post_permalink, permalink_anchor, permalink_single_rss

See also index of Function Reference and index of Template Tags.