Skip to content

Instantly share code, notes, and snippets.

@tinotriste
Last active March 22, 2017 19:06
Show Gist options
  • Save tinotriste/5388189 to your computer and use it in GitHub Desktop.
Save tinotriste/5388189 to your computer and use it in GitHub Desktop.
Wordpress: Get post/page slug
<?php
// Custom function to return the post slug
function the_slug($echo=true){
$slug = basename(get_permalink());
do_action('before_slug', $slug);
$slug = apply_filters('slug_filter', $slug);
if( $echo ) echo $slug;
do_action('after_slug', $slug);
return $slug;
}
?>
<?php if (function_exists('the_slug')) { the_slug(); } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment