Skip to main content

As per other answers, slug is stored in the post_name property. While it could be accessed directly, I prefer the (underused) get_post_field() function for accessaccessing post properties which have no proper API for them.

It requires post provided explicitly and doesn't default to the current one, so in full for the current post it would be:

$slug = get_post_field( 'post_name', get_post() );

As per other answers slug is stored in post_name property. While it could be accessed directly I prefer the (underused) get_post_field() function for access post properties which have no proper API for them.

It requires post provided explicitly and doesn't default to the current one, so in full for current post it would be:

$slug = get_post_field( 'post_name', get_post() );

As per other answers, slug is stored in the post_name property. While it could be accessed directly, I prefer the (underused) get_post_field() function for accessing post properties which have no proper API for them.

It requires post provided explicitly and doesn't default to the current one, so in full for the current post it would be:

$slug = get_post_field( 'post_name', get_post() );
Source Link
Rarst
  • 100k
  • 10
  • 161
  • 298

As per other answers slug is stored in post_name property. While it could be accessed directly I prefer the (underused) get_post_field() function for access post properties which have no proper API for them.

It requires post provided explicitly and doesn't default to the current one, so in full for current post it would be:

$slug = get_post_field( 'post_name', get_post() );