Advertise here: Contact FM.


How do I fetch the slug, sans domain, in WordPress/PHP?
August 7, 2006 8:26 PM   RSS feed for this thread Subscribe

Learning my way around WordPress. How do I fetch the slug text, sans domain, in WordPress/PHP?

Neither the docs nor Google seem to have an answer for me.

I don't, for example, want the_permalink(), which returns a fully-qualified URL. I want just the slug text, as bolded below:

http://www.domainypants.com/06/07/31/this-is-the-slug/

I have enough programming acumen to figure out how to strip this out of the larger permalink if necessary, but I'd like to know, definitively, if I need to or if WordPress actually makes this available out of the box.
posted by cortex to technology (5 comments total) 1 user marked this as a favorite
Does this work?
$post->post_name
posted by misterbrandt at 8:39 PM on August 7, 2006


!

tests it

Hugs! I swear I tried that already, but I was clearly wrong.

You're not a gweeper, are you?
posted by cortex at 8:47 PM on August 7, 2006


Here is another post that seems to confirm the $post->post_name is what you are looking for:

function get_the_slug() {
global $post;
if ( is_single() || is_page() ) {
return $post->post_name;
} else {
return "";
}
}


on preview, cool. glad it actually works for reals.
and wtf is a gweeper?
posted by misterbrandt at 8:50 PM on August 7, 2006


Something that a different Josh Brandt would self-identify as. Mystery resolved!
posted by cortex at 8:57 PM on August 7, 2006


ah. well, josh power, and all that!
posted by misterbrandt at 9:07 PM on August 7, 2006


« Older iTunesFilter: Easy way to con...   |   What is your experience with t... Newer »
This thread is closed to new comments.


Related Questions
Any tools for posting to multiple blogs? August 13, 2008
MT PHP API? July 19, 2006
Which PHP-based blogging tool should I use? March 6, 2006
Titles in EventCalendar? February 24, 2006
Wordpress and comment placement May 26, 2004