Posted By

almendro on 12/20/12


Tagged

wordpress wp


Versions (?)

WP body id width post-name or category-nicename


 / Published in: PHP
 

Add an ID to the body tag.

  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  

You need to login to post a comment.