Last active
January 28, 2021 20:29
-
-
Save tinotriste/5388318 to your computer and use it in GitHub Desktop.
Wordpress: Display a page parent's slug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Display a page parent's slug | |
$post_data = get_post($post->post_parent); | |
$parent_slug = $post_data->post_name; | |
echo $parent_slug; | |
?> |
You can also use get_post_ancestors()
as discussed on the WP Codex.
This could be simplified even further making use of get_post_field()
$parent_slug = get_post_field( 'post_name', $post->post_parent );
Thanks @Xhynk
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
THANK YOU! Just what I was trying to do, saved my day 👍