Nel tutorial di oggi creeremo 2 funzioni che ci permetteranno di conoscere se una pagina è figlia di un'altra pagina oppure se è un genitore.
Inserite il seguente codice all'interno del file functions.php del vostro tema WordPress.
// Check if page is direct child function is_child($page_id) { global $post; if( is_page() && ($post->post_parent == $page_id) ) { return true; } else { return false; } } // Check if page is an ancestor function is_ancestor($post_id) { global $wp_query; $ancestors = $wp_query->post->ancestors; if ( in_array($post_id, $ancestors) ) { return true; } else { return false; } }



Leave Your Response