WordPress.org

Make WordPress Core

Opened 5 months ago

Closed 5 months ago

Last modified 5 months ago

#23351 closed feature request (duplicate)

Add the_slug() and get_the_slug()

Reported by: iandunn Owned by:
Priority: normal Milestone:
Component: Template Version:
Severity: normal Keywords:
Cc:

Description

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)

comment:1 iandunn5 months ago

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

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

comment:2 helen5 months ago

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

comment:3 iandunn5 months ago

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