WordPress: Get the root page ID


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

Get the ID of the root (oldest ancestor, parent without parents) page relative to the current page in a WordPress page template.

Can be helpful for use with wp\_list\_pages() to create navigation markup.


Copy this code and paste it in your HTML
  1. <?php $root_page_id = ( empty( $post->ancestors ) ) ? $post->ID : end( $post->ancestors ); ?>

URL: http://codex.wordpress.org/Template_Tags/wp_list_pages#List_subpages_even_if_on_a_subpage

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.