| | 122 | * Display the slug of the current post in the WordPress Loop, or an arbitrary post. |
| | 123 | * |
| | 124 | * @since |
| | 125 | * |
| | 126 | * @param int $id Optional. ID of an arbitrary post. If none is given, uses the value of the current post inside the Loop |
| | 127 | */ |
| | 128 | function the_slug( $id = 0 ) { |
| | 129 | echo apply_filters( 'the_slug', get_the_slug( $id ) ); |
| | 130 | } |
| | 131 | |
| | 132 | /** |
| | 133 | * Retrieve the slug of the current post in the WordPress Loop, or an arbitrary post. |
| | 134 | * |
| | 135 | * @since |
| | 136 | * |
| | 137 | * @uses $post |
| | 138 | * @param int $id Optional. ID of an arbitrary post. If none is given, uses the value of the current post inside the Loop |
| | 139 | * @return string|false String if post slug was retrieved, or false if it wasn't |
| | 140 | */ |
| | 141 | function get_the_slug( $id = 0 ) { |
| | 142 | global $post; |
| | 143 | |
| | 144 | if( $id ) { |
| | 145 | $arbitrary_post = get_post( $id ); |
| | 146 | $slug = is_a( $arbitrary_post, 'WP_Post' ) ? $arbitrary_post->post_name : false; |
| | 147 | } else { |
| | 148 | $slug = isset( $post->post_name ) ? $post->post_name : false; |
| | 149 | } |
| | 150 | |
| | 151 | return apply_filters( 'get_the_slug', $slug ); |
| | 152 | } |
| | 153 | |
| | 154 | /** |