Posted By

erikportin on 05/20/11


Tagged

php wordpress headerphp


Versions (?)

Check first parent of page in Wordpress and add body id


 / Published in: PHP
 

  1. <?php
  2. if ( is_page() && $post->post_parent ) {
  3. $id = get_the_ID();
  4. $a = get_ancestors( $id, 'page' );
  5. $root=count($a)-1;
  6. $rootId = $a[$root];
  7. }
  8. else {
  9. $rootId = get_the_ID();
  10. }
  11. ?>
  12.  
  13.  
  14. <body <?php body_class(); ?> id="root-id-<?php echo $rootId ?>">

Report this snippet  

You need to login to post a comment.