get_permalink

PERMALINK TAG

What It Does

Gathers the post’s permalink for use in PHP. get_permalink can be used either inside or outside The Loop. If you simply wish to get the permalink for the current post within The Loop, you can use the_permalink.

Code

You can obtain the permalink for the current post within The Loop by using the following:

<?php get_permalink(); ?>

You can also obtain the permalink for any post inside or outside The Loop by inserting its numerical ID:

<?php get_permalink(ID); ?>

Example

To display the permalink for the current post:

<?php echo get_permalink(); ?>

To display the permalink for any post you wish, just enter its numerical ID:

<a href=”<?php echo get_permalink(1); ?>”>My First Post</a>