Get WP Page Slug

/ Published in: PHP
Save to your folder(s)

Function to get wordpress post/page slug to be used on for custom class etc

Copy this code and paste it in your HTML
  1. // Put in Functions.php
  3. function the_slug() {
  4. $post_data = get_post($post->ID, ARRAY_A);
  5. $slug = $post_data['post_name'];
  6. return $slug; }
  8. // Put where you want to show in page or single etc. Use for custom class for each page
  10. <?php echo the_slug(); ?>

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.