• Hey guys, sorry for this noob question, but I currently can’t find anything on this topic. It should be very easy to answer, thanks in advance if someone choses to do so!

    Using <?php the_permalink() ?> gives me the full link of the page displaying. What do I have to use to get the NAME of the page (meaning the last part of the permalink). I also know how to get the ID, but I need the name itself (not the TITLE). Thanks so much!!

Viewing 3 replies - 1 through 3 (of 3 total)
  • If you mean showing the page name in your php file? You’d just use <?php the_title(); ?>, and that will grab it for you. Wrap it in an h1 or h2 (or whatever) tag, and that’ll display it.

    Best,
    Connor
    [Signature removed by moderator per forum rules.]

    Thread Starter creasy

    (@creasy)

    Thanks for your answer, but no, not the title, the name (or “slug” as I found out it is obviously called).
    So, I use permalinks.. and the url is for example: http://www.url.com/blah/page-name
    So I need to use “page-name” in my template file.
    I know the title is basically the page name, but it obviously is formatted (since it says “Page Name”).
    Thanks again!

    $post_obj = $wp_query->get_queried_object();
    $post_ID = $post_obj->ID;
    $post_title = $post_obj->post_title;
    $post_name = $post_obj->post_name;

    And then $post_name is what the slug is, so echo it out and wrap it in whatever tag you want.

    Is that what you were looking for? If not, what are you trying to do, specifically?

    Best,
    Connor
    [sig moderated as per the Forum Rules]

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get name of page for template’ is closed to new replies.