Support » How-To and Troubleshooting » [Resolved] Page slug

[Resolved] Page slug

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 ‘[Resolved] Page slug’ is closed to new replies.
Skip to toolbar