Support » Fixing WordPress » Get post-name

  • Is there an elegant way to get the post-name for a Page? For example, the post-name for something titled “Page Title” would be “page-title”. Searching through the include pages, I saw a field that has what I need.

    However, I don’t know how to get the current Page object. I’ve also found a get_page() function, but I’m not sure how to handle that to achieve my goal.

    Thanks for any help!

Viewing 1 replies (of 1 total)
  • Try

    <?php $pagename = get_query_var('name'); ?>

    $pagename will hold the ‘Page slug’ value. If you only need to display it directly:

    <?php echo get_query_var('name'); ?>

    This only works on a blog with a custom permalink structure. Within The Loop you can access it up through the $post array using $post->post_name .

Viewing 1 replies (of 1 total)
  • The topic ‘Get post-name’ is closed to new replies.