I want to add a div between the links in my Wordpress menu (not on the ends, just in between). I am using the following code to bring in my menu:
html
<?php wp_nav_menu( array( 'container_class' => 'main-nav', 'theme_location' => 'primary' ) ); ?>
functions.php
/* Register 'primary' navigation */
function wptutsplus_register_theme_menu() {
register_nav_menu( 'primary', 'Main Navigation Menu' );
}
add_action( 'init', 'wptutsplus_register_theme_menu' );
The output I'm looking for is the following:
link 1
<div class="divider"></div>
link 2
<div class="divider"></div>
link 2
This is how you get result https://www.screencast.com/t/APLrCeHCxLU.
You can try following code:-
wp_nav_menu( array( 'container_class' => 'main-nav','theme_location' => 'primary','after' => '<div class="divider"></div>') ) );
Related
I am trying to get a menu with few links, and show their/link/page featured image. following is my code for functions.php.
function register_my_menus() {
register_nav_menus(
array(
'main-menu' => __( 'Main Menu' ),
'useful-links' => __( 'Userful Links' )
)
);
}
add_action( 'init', 'register_my_menus' );
and this is where i am calling it in the page.
<?php wp_nav_menu( array( 'theme_location' => 'useful-links', 'sort_column' => 'menu_order', 'container_class' => 'useful-links', 'menu'=>'Posts Menu' ) ); ?>
i know something is missing but kindly advice. my page look and feel allow 6 links and their images.
thanks
This should be in your functions.php to register the menu within WordPress.
if (!function_exists('wp_basicTemplateSetup')) {
function wp_basicTemplateSetup() {
// Register the Main Menus into WordPress
register_nav_menus(array(
'primary' => __('Main Menu', 'theme-name'),
));
}
}
add_action('after_setup_theme', 'wp_basicTemplateSetup');
In your theme, where the menu is sitting you need to tell the menu function, which menu to look for. So..:
// Variable that tells WordPress which menu to use, look at "Theme Location"
// Put this variable either at the top of your theme, of right *before* the function wp_nav_menu
$mainmenu = array(
'theme_location' => 'primary',
'container' => false,
'menu_class' => 'some-menu-css-class',
'depth' => 2
);
// The WordPress menu function
<?php wp_nav_menu($mainmenu); ?>
These 3 components are necessary to get your WordPress menu working.
I want to add a extra item like my logo before HOME item on the main nav.
My Wordpress menu looks like this
HOME | ABOUT | BLOG | CONTACT
$nav_args = array(
'theme_location' => 'nav',
'container' => 'none',
'menu_class' => 'level-1',
'depth' => apply_filters( 'yit_main_nav_depth', 3 ),
);
if ( has_nav_menu( 'nav' ) )
$nav_args['walker'] = new YIT_Walker_Nav_Menu();
wp_nav_menu( $nav_args );
this is the view
<div id="nav">
<div class="container">
<?php do_action( 'yit_main_navigation') ?>
</div>
</div>
I have solve this by adding the following code into my function.php
add_filter( 'wp_nav_menu_items', 'add_logo_nav_menu', 10, 2 );
function add_logo_nav_menu($items, $args){
$newitems = '<li><a title="logo" href="#">LOGO</a></li>';
$newitems .= $items;
return $newitems;
}
I've created one menu in Norwegian menu_no and one in English menu_en.
I can see that my theme supports only one menu, but I'm not planning on using more that one menu at a time. So when user selects English language, how can I change the active menu?
I've not found anything on Google and I can't find the right function in nav-menu.php.
UPDATE
I found quite a simple solution for my problem. I just had to think a bit differently. In my functions.phpI added this code:
add_action('init', 'register_menus');
function register_menus(){
register_nav_menus( array(
'menu_no' => 'Norwegian menu',
'menu_en' => 'English menu',
) );
}
and in my header.php file I use this code:
global $lang;
$args = array(
'theme_location' => 'menu_'.$lang,
'container' => false
);
<?php wp_nav_menu($args); ?>
Voila. I'll post it as answer later - if not anyone else comes up with a better idea.
Here is How You Can Do That.
Past this code to function.php file
// Register Navigation Menus
function custom_navigation_menus() {
$locations = array(
'first_menu' => __( 'Menu for English language', 'text_domain' ),
'second_menu' => __( 'Menu for Other Language', 'text_domain' ),
);
register_nav_menus( $locations );
}
// Hook into the 'init' action
add_action( 'init', 'custom_navigation_menus' );
You can customize the above code.
Now use wp_nav_menu function to display anywhere you want like this
<?php
wp_nav_menu( array(
'menu' => 'primary',
'theme_location' => 'first_menu',
);
?>
<?php
wp_nav_menu( array(
'menu' => 'secondary',
'theme_location' => 'second_menu',
);
?>
You can display each menu in different places. Now you to Option in you menu Primary and Secondary
I have been working on a site to change from HTML To Wordpress CMS...so got completed everything...Now stuck in one problem..and that is that I have declared the Main Navigation and Footer Navigation correctly (according to me) in functions.php file as :
/* Register Nav Main Menu */
register_nav_menus (array('main-nav' => 'Main Navigation'));
register_nav_menus (array('footer-nav' => 'Footer Navigation'));
while I am calling the both menus in correct way as for main-nav I am calling it in header.php as :
wp_nav_menu( array( 'menu' => 'main-nav' ));
while calling the footer-nav as following in footer.php as :
wp_nav_menu( array( 'menu' => 'footer-nav' ));
but in both places only main-nav is shown...so what did I do wrong please?..Need a hand to fix it...!
Waiting for your replies..!
Here is live link to the site as : http://www.huntedhunter.com/minaterra/
try changing:
wp_nav_menu( array( 'menu' => 'footer-nav' ));
to
wp_nav_menu( array( 'theme_location' => 'footer-nav' ));
I'm building a membership website on Wordpress and would like to show a different navigation menu to logged in users.
Here is the current PHP code that displays the menu :
<?php /* Our navigation menu. */ ?>
<?php if ( isset ($options['admired_remove_superfish']) && ($options['admired_remove_superfish']!="") )
wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary' ) );
else
wp_nav_menu( array( 'container_class' => 'menu-header', 'theme_location' => 'primary', 'menu_class' => 'sf-menu','fallback_cb' => 'admired_page_menu' ) );?>
Here's the PHP code that needs to replace that code :
<?php
if ( wp_emember_is_member_logged_in() ) {
wp_nav_menu( array( 'menu' => 'logged-in-members' ) );
} else {
wp_nav_menu( array( 'menu' => 'normal-visitor-menu' ) );
}
?>
If I just replace the old code, with the newer code it will work, but the formatting is off. I need the Superfish part in the current code, but I'm not sure how to make it work in PHP.
I know this may be a little confusing, but I would appreciate any help. Thanks!
P.S. This is a tutorial from the plugin's site. I've been following it, but I somehow need to keep the Superfish in there. I'm sure not sure how to do it.
http://www.tipsandtricks-hq.com/wordpress-membership/show-different-navigation-menu-to-your-members-and-non-members-551
The 'menu_class' => 'sf-menu' will add the sf-menu class for the menu (<ul class="sf-menu">) and super fish plugin will use this class to identify the menu and style will be applied which has been declared in the super fish plugin's css
<?php
if ( wp_emember_is_member_logged_in() ) {
wp_nav_menu( array( 'menu' => 'logged-in-members', 'menu_class' => 'sf-menu' ) );
} else {
wp_nav_menu( array( 'menu' => 'normal-visitor-menu', 'menu_class' => 'sf-menu' ) );
}
?>
For more see this.
Considering the code above, the only thing that is changing is the actual location of the menu. The (existing) code is showing that you want the menu that's in 'theme_location' => 'primary' where, as you have a hardcoded menu you want to use, and you're selecting it with 'menu' => 'loggged-in-members' The finished result will be...
<?php
if ( wp_emember_is_member_logged_in() ) {
wp_nav_menu(
array(
'container_class' => 'menu-header',
'menu' => 'logged-in-members',
'menu_class' => 'sf-menu',
'fallback_cb' => 'admired_page_menu'
)
);
} else {
wp_nav_menu( array( 'menu' => 'normal-visitor-menu' ) );
}
?>