WordPress - Get Current Page Parent


/ Published in: PHP

Returns the page object of the parent of the current page.


Copy this code and paste it in your HTML
  1. function get_parent_page() {
  2. global $post;
  3. $topParent = $post;
  4. while ($topParent->post_parent) {
  5. $topParent = $topParent->post_parent;
  6. }
  7. return get_page($topParent);
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.