How To Add Or Move A Logo Image To Any Nav Menu

In this post, i’ll show you several different ways to add a logo image to either your primary or secondary navigation menu. Try this code if you only want to move your site title into your menu.

You’ll also be able to float your logo to the left or right of your menu items.

On top of this, you can easily change the position your image sits in your menu.

logo menu genesis

Here’s the PHP & CSS code you need to add at the end of your child themes functions.php & style.css files.

Other Cool Stuff You Can Do With Your Logo


Comments

31 responses to “How To Add Or Move A Logo Image To Any Nav Menu”

  1. […] How To Add A Logo Image To Any Nav Menu […]

  2. Hi Brad,

    I’ve got the logo sitting where I want it to in the nav bar now, but like the commenter above, I want to make the logo hyperlink back to the front page.

    I’ve tried the code you replied with above but don’t understand exactly where to add my URL and the image address. Can you please help? Thanks.

    [code]
    add_filter( ‘wp_nav_menu_items’, ‘wpsites_add_logo_nav_menu’, 10, 2 );
    function wpsites_add_logo_nav_menu( $menu, stdClass $args ){

    if ( ‘primary’ != $args->theme_location )
    return $menu;

    $menu .= sprintf( ‘%s’, __( ”) );

    return $menu;

    }

    [/code]

    1. Brad Dalton Avatar
      Brad Dalton

      Are you a member of WP Sites Amber?

  3. first Avatar

    Hi Brad,

    Thanks for the code, it works perfectly.
    But I would like to create an grey hover effect when I pass the mouse on the logo, how do I do that please?

    Best,

    1. Brad Dalton Avatar
      Brad Dalton

      I think something like this should work but didn’t test it.
      [code]
      .nav-logo:hover {
      opacity: 0.4;
      filter: alpha(opacity=40);
      }
      [/code]

  4. I am trying to put a larger image than the height of the Nav Bar, The Nav Bar is adjusting to make up for the space, now I have a very high nav bar, is there a way to keep the nav bar the same height, but have the image over hang on the top and bottom?

    1. Brad Dalton Avatar
      Brad Dalton

      Yes but i haven’t written about how to do that ye so try something like this http://cyberchimps.com/forum-topic/overhang-header-image/

  5. Not sure why, but the code didn’t paste in quite right. Basically, though, I just inserted the hyperlink code within the I’ll try again…

  6. Hi Brad,

    Just wanted to let you know that I fixed the issue. The needed to be inside the tag (see code below).

    Thanks so much for all of your assistance!

    1. Brad Dalton Avatar
      Brad Dalton

      Happy to help Michelle.

  7. Hi — Thank you so much for this excellent code! One question — how can I make this logo hyperlink to my homepage?

    1. Brad Dalton Avatar
      Brad Dalton

      Hello Michelle

      Code updated: Simply add your logo.png image file to your child themes images folder and use this code.

      This is not the only way to code this function.

      You could use a different class so it validates for W3 Standards (which i will do and update the code) and you could print the HTML for the image differently.

      Then add list-style-type to the declarations like this:

      [code]
      .nav-logo {
      float: left;
      margin-right: 20px;
      margin-top: 20px;
      list-style-type: none;
      }
      [/code]

      And that now validates for W3.

      1. Hi Brad,

        Thanks so much for addressing this so quickly! I’m a little unclear on what you’re saying about validating for W3, however. Are you suggesting using the code you just provided with the modified CSS (the one that includes list-style-type: none;) or are you saying that the function would need to be different altogether to validate for W3?

        Also, I’m trying to ensure that when I insert the logo in the navigation menu, it remains to the left of all of the other links in the menu (like the sample images you show). But currently, the logo seems to jump to a second line below the other links in the menu if there are too many items in the menu or if the page size is reduced. How can I tell the function to load the logo first and always make it the first item at left in the menu?

        Thanks again for all of your help!

        Michelle

        1. Brad Dalton Avatar
          Brad Dalton

          You can skip that part as i i have updated the code and tested it.

          There’s many different ways to write code that does the same thing.

          PHP is only one side of the solution but doesn’t tell the browser where to output the HTML so you also need to add CSS.

          Its impossible to provide CSS code that works on every theme as there’s 1000’s which are all coded differently.

          I can only provide sample CSS which may need tweaking and/or additions of extra declarations.

          Little bit of work on your behalf is required.

          Watch out for a new post which includes another option for the CSS in a similar solution.

          Something like this may work if you change some of the values:

          [code]
          .search-form {
          position: absolute;
          right: 105px;
          padding-top: 15px;
          width: 360px;
          list-style-type: none;
          }
          [/code]

          1. Hi Brad,

            I apologize if I was unclear. The search field is fine and the logo is lining up on the left side. But, for some reason, the logo is showing up on a second line below the other menu items. Basically, I’m trying to get the logo to show at the beginning of the menu (the first item with subsequent menu items aligned to the right of the logo).

            How do I make the logo the first to display in the list rather than the last (as it currently is)?

            I understand that CSS is theme/site specific, but this seems like something that should be inserted in the function to tell the logo where to load within wp_nav_menu_items.

            Thanks again for all of your help!!

            Michelle

          2. Brad Dalton Avatar
            Brad Dalton

            The class is generated by the PHP function and then you use that class in a CSS rule with a declaration that includes a property and value.

            The code i published today may work. http://wpsites.net/web-design/how-to-position-get-search-form-in-nav-menu/

  8. Thank you for this tip.
    However in my twenty thirteen chip theme, my logo goes to the right of the navbar instead of left.
    What do you think I can do, to put it on the left ?
    Many thanks!

    1. Brad Dalton Avatar
      Brad Dalton

      All themes use different CSS so you will need to tweak the CSS.

      Change float:right to float:left.

      1. Actually this is already “float:left”. I copied/pasted exactly the code you wrote on your website

        1. Brad Dalton Avatar
          Brad Dalton

          Strange because the screenshot near the end of the post shows the result that it floats left when tested on Twenty Thirteen.

          What is this theme that you mentioned?

          twenty thirteen chip theme

          1. I finally found my mistake! I did not put the css code in the right place, we have to copy it below the .navbar css.
            Now my logo is on the left.
            Thanks 🙂

          2. Brad Dalton Avatar
            Brad Dalton

            That’s right.

            Always at the end of the file before the start of the Media Queries.

            That’s why its called a cascading style sheet!

    2. Sorry, it was twenty thirteen “child” theme (not chip!)

      1. Brad Dalton Avatar
        Brad Dalton

        Those little details are important when it comes to code. hahaha

  9. […] How To Add A Logo Image To Any Nav Menu […]

  10. Joyce Grace Avatar
    Joyce Grace

    Something I really want to try is turning the logo into an SVG, importing that into the IconMoon app, making it part of an icon-font set and then resolving the retina display problem that way. The thing I haven’t tested yet is whether the CSS class on the WordPress menu item would work. I tried inserting a character code into the “Navigation Label” area of a WordPress Menu but that didn’t work, it won’t accept it. I should try a div in that area…a while ago HTML worked in Page Titles….hmmm….

    This would not work with multi-coloured logos but would be a really great solution for one-colour logos….

    1. Brad Dalton Avatar
      Brad Dalton

      Hello Joyce

      Interesting question.

      I guess you’ve already tried adding a class to the menu item and doing it that way?

  11. […] Denne artikel er en dansk oversættelse af  artikel på til wpsites.net […]

  12. Wayne Plant Avatar
    Wayne Plant

    Great stuff Brad!
    I love these posts for the tips and information on modifying WP websites.
    Keep it up.

    Regards,

    Wayne Plant

    1. Brad Dalton Avatar
      Brad Dalton

      Thanks for the kind words Wayne

Leave a Reply

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.