Category Archives: Wordpress

Display the Post or Page slug in a WordPress theme template

It’s crazy that you have to add this function in yourself. But… you do. Firstly open up functions.php and paste the following in anywhere, like, ahh, at the very bottom: function the_slug() { $post_data = get_post($post->ID, ARRAY_A); $slug = $post_data['post_name']; return $slug; } And now, in your template, display the slug thus: <?php echo the_slug(); [...]