I want to add an image to a parent page and all it's children including 2nd level grandchildren. I don't want the image on any other page.
here's what I have so far:
if(is_page() || is_single()) {
global $post;
if ($post->post_parent == '27' || $post->ID == '27') {
$ntest='<div class="clearlogo"><img alt="nodal Clear logo" width="150" src="'.get_stylesheet_directory_uri().'/images/nodal-clear-logo.png"></div>';
}else{
$ntest='';
}
This works for 1st level and the parent, but not grandchildren. I thought about adding the 2nd level page ids, but thought there has be be a better way.
I feel like I'm missing something easy.
I'm writing this in a function that will add it to the content with the_content (full content below):
function rt_before_after($content) {
if(is_page() || is_single()) {
global $post;
if ($post->post_parent == '27' || $post->ID == '27') {
$ntest='<div class="clearlogo"><img alt="nodal Clear logo" width="150" src="'.get_stylesheet_directory_uri().'/images/nodal-clear-logo.png"></div>';
}else{
$ntest='';
}
$beforecontent = $ntest.'<h1 class="title">'.get_the_title().'</h1>';
$fullcontent = $beforecontent . $content;
} else {
$fullcontent = $content;
}
return $fullcontent;
}
add_filter('the_content', 'rt_before_after');