Get page permalink and title outside the loop in wordpress

Posted by Aakash Chakravarthy on Stack Overflow See other posts from Stack Overflow or by Aakash Chakravarthy
Published on 2010-06-13T05:34:17Z Indexed on 2010/06/13 5:42 UTC
Read the original article Hit count: 479

Filed under:
|
|
|
|

Hello,

How to Get page permalink and title outside the loop in wordpress.

I have a function like

function get_post_info(){
  $post;
  $permalink = get_permalink($post->ID);
  $title = get_the_title($post->ID);
  return $post_info('url' => $permalink, 'title' => $title);
}

when this function called within the loop, it returns the post's title and url.

When it is called outside the loop. It is not returning the current page's title and url. When called in home page it should return the home page's title and url

How to get like this ? instead this function returns the latest posts title and url

© Stack Overflow or respective owner

Related posts about Wordpress

Related posts about url