This page redirects to an external site: http://developer.wordpress.org/reference/functions/get_permalink/
Languages: English • 日本語 (Add your language)
Returns the permalink to a post or page for use in PHP. It does NOT display the permalink and can be used outside of The Loop. On failure, it returns false.
In a Plugin or Theme, it can be used as early as the setup_theme Action. Any earlier usage, including plugins_loaded, generates a Fatal Error.
Note that 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
<?php $permalink = get_permalink( $id, $leavename ); ?>
<a href="<?php echo get_permalink( 268 ); ?>">My link to a post or page</a>
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: <?php echo get_permalink(); ?>
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 esc_url( get_permalink(1) ); ?>">About MyBlog</a></li>
<li><a href="<?php echo esc_url( get_permalink(10) ); ?>">About the owner</a></li>
</ul>
</li>
</ul>
This shows how you can you can get the permalink with the page title instead of the ID.
<a href="<?php echo esc_url( get_permalink( get_page_by_title( 'Monthly Events' ) ) ); ?>">Monthly Events</a>
Since: 1.0.0
get_permalink() is located in wp-includes/link-template.php.
get_permalink(), the_permalink(), post_permalink(), permalink_anchor(), permalink_single_rss()