Skip to content

Instantly share code, notes, and snippets.

@DanCanetti
Created May 25, 2021 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanCanetti/0871d2df7052b78dd9af2a7278ae6828 to your computer and use it in GitHub Desktop.
Save DanCanetti/0871d2df7052b78dd9af2a7278ae6828 to your computer and use it in GitHub Desktop.
WordPress is_child by slug (add to functions.php)
// Is child
function is_child($post_slug) {
global $post;
$parent_id = $post->post_parent;
$post_slug = get_post_field( 'post_name', $parent_id );
if( is_page() && ($post_slug) ) {
return true;
} else {
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment