Skip to content

Instantly share code, notes, and snippets.

@Blake-C
Last active September 10, 2021 17:37
Show Gist options
  • Save Blake-C/4b72b56893218c859b3b to your computer and use it in GitHub Desktop.
Save Blake-C/4b72b56893218c859b3b to your computer and use it in GitHub Desktop.
Get WordPress Current Page Slug / Parent Slug / Parent ID
<?php
function the_parent_slug() {
global $post;
if($post->post_parent == 0) return '';
$post_data = get_post($post->post_parent);
return $post_data->post_name;
}
function the_current_page_slug() {
global $post;
return $post->post_name;
}
function the_parent_page_id() {
global $post;
$parent_page_id_is = get_post($post->post_parent);
return $parent_page_id_is->ID;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment