WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is that possible to insert a text before the menu items? In this case, I want to lead a <h3> tag for the list content (like a menu title). I tried the if/else to recognize that the menu have content and show the title. But if the menu have no content, so it should not have to display the title.

Here it is:

$args = array(
  'menu'        => 'Destination • South America',
  'echo'        => false,
  'fallback_cb' => '__return_false'

if (empty($args)) {
  echo "<li></li>";
  echo "<h3>South America</h3>";
echo strip_tags(wp_nav_menu( $args ), '<li><a>');

Because I have content, so It should output:

South America

If I would not have any content, so it should not display the South America

Thank you!

share|improve this question
Why aren't you just using the "South America" or other parent text as a parent menu item, others as child item ? The thing you are trying to achieve will only comes up handy when the "Argentina, Chile" etc are being included dynamically in the menu. – Shazzad Jul 7 '14 at 16:05
That's right. I'm using Argentina, Brazil and other countries as the menu. The "South America" title appears to identify the countries in the menu. However, if I remove all the items in the menu, the "South America" (the h3) should not be display! – user3301994 Jul 7 '14 at 17:03
I think he's trying to say this is a sub navigation menu on internal pages, and it shows up everywhere. I'll add an answer to this effect. – deflime Jul 7 '14 at 18:40

Put this function into your theme's function.php file.

function is_tree($pid) { // $pid = The ID of the page we're looking for pages underneath
    global $post;
    $anc = get_post_ancestors( $post->ID );
    foreach($anc as $ancestor) {
            if(is_page() && $ancestor == $pid) {
                    return true;
    if(is_page()&&(is_page($pid))) { return true; /*we're at the page or at a sub page*/ }
    else { return false; /*we're elsewhere*/ }

Then wrap your code in:

  // put the parent id or in this case, South America's id as the parent-id
  if(is_tree('parent-id')) {
    // output your menu
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.