Last active
September 10, 2021 17:37
-
-
Save Blake-C/4b72b56893218c859b3b to your computer and use it in GitHub Desktop.
Get WordPress Current Page Slug / Parent Slug / Parent ID
This file contains hidden or 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 | |
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