Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

The below is the menu code used in the default WordPress theme of "Allure Real Estate Theme for Placester".

     `<li><a href="/">Home</a></li>
     <li><a href="<?php echo @get_permalink(get_page_by_title('About')->ID); ?  

      >">About</a>     

     </li>
     <li><a href="<?php echo @get_permalink(get_page_by_title('Search')->ID); ?

     >">Search</a></li>
     <li><a href="<?php echo @get_permalink(get_page_by_title('Blog')->ID); ?   

     >">Blog</a></li>
     <li><a href="<?php echo @get_permalink(get_page_by_title('Contact')->ID); ?

     >">Contact</a></li>
     <li><a href="<?php echo @get_permalink(get_page_by_title('Testimonials')->ID);   
     ?">Testimonials</a>`

How can I create a sub-menu in any one of the main menu items in the above code?

share|improve this question
add comment

2 Answers

A sub-menu generally is made by adding another ul/li elements inside an li, like this:

<ul>   <!-- Menu -->
    <li>Menu item 1</li>
    <li>Menu item 2</li>
    <li>Menu item 3
        <ul>  <!-- Sub Menu -->
            <li>Sub item 1</li>
            <li>Sub item 2</li>
        </ul>
    </li>
</ul>

But if you want some dropdown menu, you have to add some css, so that the submenu is hidden, and when you hover on the li with the submenu, you show the submenu.

I don't know that theme but it seems to me they don't have css for that.

The menu is build directly in the code? It's not using Wordpress Menus?

If you give a link of your site, I can help you with the css.

share|improve this answer
add comment

Is this menu hard-coded? In that case you might consider replacing this menu with an menu filled by WordPress, so you can add menu items and submenu items from within de admin.

For that, add the following code to your functions.php:

register_nav_menu( 'your-menu', __( 'Your Menu' ) );

And where your menu is now, place the following code (deleting the menu you have now):

wp_nav_menu( array( 'theme_location' => 'your-menu' ) );

Now the menu you select in the menu settings area will be shown as your menu.
And the submenu items you have added there will be added too.

share|improve this answer
add comment

Your Answer

 
discard

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.