WordPress.org

Ready to get started?Download WordPress

Forums

Get post-name (2 posts)

  1. kwarrior
    Member
    Posted 8 years ago #

    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 Page.post-name 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!

  2. Kafkaesqui

    Posted 8 years ago #

    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 .

Topic Closed

This topic has been closed to new replies.

About this Topic