WP body id width post-name or category-nicename


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

Add an ID to the body tag.


Copy this code and paste it in your HTML
  1. <?php
  2.  
  3. $body_id ="";
  4. if ( is_single() || is_page() ) {
  5. $body_id = ' id="'.$post->post_name.'" ';
  6. } else if ( is_category() ) {
  7. $category = get_the_category();
  8. $body_id = ' id="category_'.$category[0]->category_nicename.'" ';
  9. }
  10. ?>
  11. <body <?php body_class(); ?> <?php echo $body_id; ?> >

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.