Search code examples
wordpressfunctionparent-childparent

functions - if statement for parent and child


I've got following php function:

if ( ! function_exists('meteorite_sitebranding') ):
function meteorite_sitebranding() {
    $logo_light = get_theme_mod( 'logo_light', '' );
    $has_custom_logo = has_custom_logo();

    if ( $has_custom_logo || $logo_light) {
        if ( function_exists( 'the_custom_logo' ) && has_custom_logo() && is_front_page() || is_home() ) {          
            the_custom_logo();
        }
        elseif ( function_exists( 'the_custom_logo' ) && has_custom_logo() ) {
            echo '<a href="' . esc_url( home_url( '/' ) ) . '" rel="home"><img src="logo_color.png" class="custom-logo" alt="Auplo" itemprop="logo" /></a>';
        }

        elseif ( $logo_light ) {
            echo '<a href="' . esc_url( home_url( '/' ) ) . '" title="' . esc_attr(get_bloginfo('name')) . '"><img class="site-logo light" src="' . esc_url($logo_light) . '" alt="' . esc_attr(get_bloginfo('name')) . '" /></a>'; 
        }
    } else {
        echo '<div class="site-brand">';
        if ( is_front_page() && is_home() ) :
            echo '<h1 class="site-title"><a href="' . esc_url( home_url( '/' ) ) . '" rel="home">' . get_bloginfo('name', 'display') . '</a></h1>';
        else :
            echo '<p class="site-title"><a href="' . esc_url( home_url( '/' ) ) . '" rel="home">' . get_bloginfo('name', 'display') . '</a></p>';
        endif;
        echo '<p class="site-description">' . get_bloginfo('description', 'display') . '</p>';
        echo '</div>'; // /.site-brand
    }
}
endif;

the function works well. But i would like to finetune it a bit. My question is related to part:

if ( function_exists( 'the_custom_logo' ) && has_custom_logo() &&
is_front_page() || is_home() )

How can i add as a part of statement the condition of OR is_page('destination') and include all childs of that page? so e.g. Ive got page

Destination + New York + Warsaw + Dublin + Dubai

and i would like to cover all those pages. I've tried doing something like:

|| is_page('destination') || is_child('destination') but simply it doesnt work..

thanks!


Solution

  • You could use this

    function is_child($pageID) { // In functions.php
      global $post; 
      if( is_page() && ($post->post_parent==$pageID) ) {
               return true;
      } else { 
               return false; 
      }
    }
    
    if(is_child(123)) { // in your template
     echo "Child page of 123";
    }