How to add a custom item to a specific WordPress menu item position -


i have primary menu registered , displayed consists of 4 links (home, about, news, blog). want add html (a logo) in between second , third menu , wondering if possible.

here diagram: home | | logo | news | blog

i looking @ hook wp_nav_menu_items can add custom item either first position or last.

before used jquery add html since dom has loaded logo loads last , i'm trying logo show first or @ same time content of page.

php version

one way create 2 navigation menu's used.

header_menu_1 | logo | header_menu_2

within back-end, you'd need create new header location , add 2 menu items it.

then within header.php file, have code.

<?php     $args1 = array( 'menu' => 'header_menu_1' );     $args2 = array( 'menu' => 'header_menu_2' );     wp_nav_menu($args1); ?>  <img src="logo source" />  <?php     wp_nav_menu($args2); ?> 

that easiest way without using jquery or messing plugins.

wp nav menu

adding new wordpress menus

jquery version

$(document).ready(function() {     var = 1;     $('ul li').each(function() {         if(i == 2) {             $(this).after('<img src="http://www.socialtalent.co/images/blog-content/so-logo.png" width="250" />');         }         i++;     }); }); 

demo

css version

this dirty hack way of doing it.

using nth-child, select out 2nd , 3rd elements. both items more margin middle 2nd element 30px margin right , 3rd element 30px margin left.

then put div logo in position absolutely in middle.

example:

css:

#container {     width: 100%; }  ul {     display: block;     width: 100%; } li {     display: inline-block;     width: 15%;     padding: 1.25%;     margin: 1.25%;     background: blue; }  li:nth-child(2) {     margin-right:10%; } li:nth-child(3) {     margin-left: 10%; }  #container img {     width: 20%;     position: absolute;     left: 50%;     margin-left: -7.5%; } 

html:

<div id="container">     <img src="http://cdn.sstatic.net/stackexchange/img/logos/so/so-logo.png" />     <ul>         <li>home</li>         <li>home</li>         <li>home</li>         <li>home</li>     </ul> </div> 

demo


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -