Make WordPress Core

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#23351 closed feature request (duplicate)

Add the_slug() and get_the_slug()

Reported by: iandunn's profile iandunn Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Template Keywords:
Focuses: Cc:


It's not uncommon for a theme or plugin to want to use a post's slug, but the API doesn't provided a function for accessing it. There are several homegrown functions online that people are using (1, 2), but some of them are buggy or poorly written, and it seems like this is something the API should provide a consistent mechanism for accessing, just like it does for the other properties of a post.

Many of the homegrown methods didn't prefix their functions names, so there would be collisions for them if this were committed to a future release. Here are a couple ideas for addressing that:

  1. Choose different names to avoid collisions. The downside here is that the new function names wouldn't be consistent with similar functions like the_title(), the_guid(), etc.
  2. Make the new functions pluggable, so they'd only be declared if others didn't already exist.
  3. Just let collisions happen. The error PHP spits out is fairly descriptive, so it shouldn't be too hard for people to realize what's going on.

I'm leaning towards #3, but would like to hear other opinions.

I assumed there'd already be a ticket for this, but couldn't find one. If anyone knows of another, please mark this as a duplicate.

Change History (3)

#1 @iandunn
11 years ago

  • Resolution set to duplicate
  • Status changed from new to closed

Er, nevermind, just found #17134. Closing this one.

#2 @helen
11 years ago

  • Keywords needs-codex removed
  • Milestone Awaiting Review deleted
  • Version 3.5 deleted

#3 @iandunn
11 years ago

  • Component changed from Post Types to Template
  • Type changed from enhancement to feature request
Note: See TracTickets for help on using tickets.