I want to hide <h2>title</h2>
if they are not children pages.
<h2> title</h2></br>
<?php
// Globalize the $post variable;
// probably already available in this context, but just in case...
global $post;
wp_list_pages( array(
'title_li' => __(''),
// Only pages that are children of the current page
'child_of' => $post->ID,
// Only show one level of hierarchy
'depth' => 1,
) );
?>
You can use the get_children function to get all child contents of your post. If the return array is empty, there are no child pages defined:
Documentation: