LeRoy
LeRoy

Reputation: 4446

how to add menu in wordpress website

How can you add a wordpress menu? I tried everything but seems not too be working. originally I was looking for a way too add dropwon menu . e.g. I am using version 3.6.1

Dopdown menu

        <div class="nav-wrap">
<ul class="nav">
                <li class="on">
      <a href='index.html' ><?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?></a>
        </li>
          <li>
            <a href='#'>About us</a>
                  <ul class="subnav">
                    <li><a href='companyhistory.html'>Company History</a></li>
                    <li><a href='visionstatement.html'>Vision Statement </a></li>
                    <li><a href='missionstatement.html'>Mission Statement </a></li>
                    <li><a href='values.html'>Values </a></li>
                    <li><a href='ourpromisetoyou.html'>Our promise to you</a></li>
                  </ul>
          </li></ul>
          </div>

but found out this will not work on WordPress. So i tried the WordPress built in menu, but still this does not work.

Function.php

 <?php 
    function twentyten_page_menu_args( $args ) {
        $args['show_home'] = true;
        return $args;
    }
    add_filter( 'wp_page_menu_args', 'twentyten_page_menu_args' );

        // This theme uses wp_nav_menu() in one location.
        register_nav_menus( array(
            'primary' => __( 'Primary Navigation', 'twentyten' ),
        ) );

    ?>

header.php

<?php wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) ); ?><

Upvotes: 0

Views: 3948

Answers (3)

Aslam Khan
Aslam Khan

Reputation: 378

Step 1: Craete function function in your child-theme function file
Step 2: Add action admin_menu hook after create function

Step 3: After complete these , now you can enter the content inside the function. i hope now you have successfully create admin menu . :)

function admin_manage_users(){
add_menu_page('my-menu', ' Manage Users', 'Manage Users', 'manage_options', 'mymenu', 'mymenu' );
 }
       
add_action('admin_menu', 'admin_manage_users');


 function mymenu()
  {
     //Here add your html or php content
     <h1> <?php echo "Welcome To Admin Menu"; ?> </h1> 
  }

Upvotes: 1

Saranya Arun
Saranya Arun

Reputation: 99

Please try this, just put this lines of code in functions.php

  register_nav_menus( array(  
  'primary' => __( 'Primary Navigation', 'Your-theme-name' ),  
  'secondary' => __('Secondary Navigation', 'Your-theme-name')  
  ) ); 

Put this line of code in your theme where this menu should appear or header.php

  <?php wp_nav_menu( array( 'theme_location' => 'primary' ) ); ?>

Now you can able to see Menus option under Appearance. Here You have options to add menus from posts, categories, tags etc.

Upvotes: 1

Jason
Jason

Reputation: 901

In my opinion, the best way to add a navigation in Wordpress is to hard-code it. Put your code into the header.php file. What I've changed in your code below:

All wordpress pages are .php not .html (unless you are using some static pages you already made, but that would not typically be my approach.)

I discarded the "on" class. If you are trying to highlight text for the current page, this isn't going to work because "header.php" is called for every page, and no matter what page, the class "on" would be applied to the text for your home page.

I got rid of the wordpress code for displaying the wordpress menu. Don't try to use includes for a hard coded menu. Just do it by hand for a small site like this.

I added a link for your blog. This is where all of your dynamic pages will come from. (You can go into the "reading" settings in the admin console, and set your home page (a static page) and your blog page.)) Also, you can use the "blog" for anything, not just a blog. It can be your dynamic photo gallery, a support forum, etc. Or simply don't use it if you don't need a blog.

Make sure to replace "mysite.com" with your actual address. With this hardcoded menu, you should use full addresses, not relative addresses, especially if you will be using the blog.

           <div class="nav-wrap">
    <ul class="nav">
                    <li><a href='http://www.mysite.com/index.php' >Home</a></li>
              <li>
                <a href='#'>About us</a>
                      <ul class="subnav">
                        <li><a href='http://www.mysite.com/companyhistory.php'>Company History</a></li>
                        <li><a href='http://www.mysite.com/visionstatement.php'>Vision Statement </a></li>
                        <li><a href='http://www.mysite.com/missionstatement.php'>Mission Statement </a></li>
                        <li><a href='http://www.mysite.com/values.html'>Values </a></li>
                        <li><a href='http://www.mysite.com/ourpromisetoyou.php'>Our promise to you</a></li>
                      </ul>
              </li>

</ul>
<li><a href='http://www.mysite.com/blog.php' >Our Blog</a></li>
              </div>

This should give you a functioning navigation menu you can control. As for making a drop-down menu, you simply have to apply the right css. One good place to start for that would be this answer I posted to a SO question a few days ago. Decent tutorial, fairly well marked up code:

https://stackoverflow.com/questions/18924800/create-menu-in-wordpress-parent-and-child-items-but-not-pages/18925070#18925070

Upvotes: 1

Related Questions