Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get parent page id and title of current page in wordpress?

Tags:

wordpress

Here is the my code, which is not working.

global $post;
echo get_the_title( wp_get_post_parent_id( $post->post->ID ) );

but this is not working.

thank you in advance.

like image 965
Therichpost Avatar asked Apr 06 '17 07:04

Therichpost


People also ask

How do I get a parent page title in WordPress?

While there's probably a plugin for this, we have created a quick code snippet that you can use to get parent page title in WordPress. $parent_title = get_the_title( $post ->post_parent);

How do I get current page info in WordPress?

Bookmark this question. Show activity on this post. $page_object = get_queried_object(); $page_id = get_queried_object_id(); // "Dirty" pre 3.1 global $wp_query; $page_object = $wp_query->get_queried_object(); $page_id = $wp_query->get_queried_object_id();

Are WordPress pages parent?

What Is a Parent Page? A WordPress parent page is a top-level page in the site's hierarchy. The group of sub-pages nestled under it are called child pages.

How do I find the current page ID in Woocommerce?

php if(is_shop()){ $page_id = woocommerce_get_page_id('shop'); }else{ $page_id = $post->ID; } ?> Hope this will help you.


3 Answers

For parent page id

$post->post_parent;

For current page title

$post->post_title;
like image 151
Ritz Cool Avatar answered Oct 26 '22 00:10

Ritz Cool


For parent page id

<?php
  echo wp_get_post_parent_id(get_the_ID());
?>    
like image 43
ejaz parvi Avatar answered Oct 25 '22 23:10

ejaz parvi


In Gutenberg:

wp.data.select('core/editor').getEditedPostAttribute('parent')

Hope will be helpful to someone

like image 23
khandaniel Avatar answered Oct 26 '22 00:10

khandaniel