Created
July 17, 2014 19:09
-
-
Save ruthtillman/7b0337cddfed76421b84 to your computer and use it in GitHub Desktop.
Wordpress: globally-isolating a page's slug.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function get_the_slug( $id=null ){ | |
| if( empty($id) ): | |
| global $post; | |
| if( empty($post) ) | |
| return ''; // No global $post var available. | |
| $id = $post->ID; | |
| endif; | |
| $slug = basename( get_permalink($id) ); | |
| return $slug; | |
| } | |
| /* Actually returns slug kinda */ | |
| /** | |
| * Display the page or post slug | |
| * | |
| * Uses get_the_slug() and applies 'the_slug' filter. | |
| */ | |
| function the_slug( $id=null ){ | |
| echo apply_filters( 'the_slug', get_the_slug($id) ); | |
| } | |
| /* This is how to use slug */ | |
| /* <?php the_slug(); ?> */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment