Get wordpress permalink outside of the loop

December 15, 2008 · Print This Article

If you want to get a permalink outside of the loop. Here’s how to do it easily.

To get a permalink outside of the loop, you have to use the get_permalink() function. That function takes a single argument, which is the ID of the post you’d like to get the permalink:

<a href="<?php echo get_permalink(10); ?>" >Read the article</a>

You can also use this function with the $post global variable:

<a href="<?php echo get_permalink($post->ID); ?>" >Read the article</a>

Your choice for site templates and wordpress themes


One Response to “Get wordpress permalink outside of the loop”

  1. No Fat Clips!!! : Mail and Comments on September 24th, 2009 2:43 pm

    […] In other news, I’ve added the canonical URL to single post pages, so that Google webmaster tools should stop bothering about duplicate pages. Some precious info found at Live Experience. […]

Got something to say?

You must be logged in to post a comment.