Support » Fixing WordPress » Page slug

  • Resolved brockangelo


    I am building a CMS and am trying to build a “Department” template. I am designing WordPress so that my Department pages have the same slug as their respective category and link categories.

    In the template I would like to extract the permalink slug of the page so that it can be used with the category and link categories.

    For example, at this page:


    I want to be able to extract “human-resources”, put it into a variable, and use it with:


    The permalink_anchor template tag did not turn up any results, and I poured over the template tags. I suppose if this isn’t supported by the wp-core I’ll just extract using php.

    Anyone know of some other way to do this? It seems like I am missing something obvious.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Well shoot, I marked this as resolved before I submitted this and I lost my last post 🙁

    Here is what I found:

    PHP has a built in function called “substr”. If you enter the following:

    echo substr(get_permalink(),35);

    it will extract data from the string starting at the 35th character. In my case, the blog url + category = 35th character. Voila! I have the slug of the page.

    This is not the cleanest, and I’ll have to change it before I take the site live. Anyone have a better idea?

    Okay – here is the clean solution if you need to get your page or post slug for use with category slugs:

    <?php echo $post->post_name; ?>

    TA-DAAAA! 🙂
    I knew there had to be an easier way. This outputs the slug, so you can plug this into a variable called $slug for use all throughout your template code.

    thank you so much for this!

    I wish this was in the documentation somewhere. I searched for slug, posttitle, sanitize, and permalink, over and over again trying to find out how to access this. I guess I should have looked at the tables. But I figured it was a variable I could access.

    thanks again. $post->post_name; is a life saver…

    Nice one!

    That’s saved me some searching, thanks.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Page slug’ is closed to new replies.