If you’re building out custom functionality or a plugin in WordPress, chances are you’re eventually going to need to get a permanent link to a post while outside of the loop.

Here’s how…

function my_function() {
  global $post;
  get_permalink($post->ID);
}

Easy.