remove ul from wp nav menu wordpress - wordpress

I am using twenty thirteen theme. I am using wp_nav_menu to display menu items. I need to remove the container div and ul from wp nav menu. I tried this.
wp_nav_menu( array( 'container' => '', 'items_wrap' => '%3$s', 'theme_location' => 'primary' ) );
But it's not working. How to fix this?

add false for container
wp_nav_menu( array( 'container' => false, 'items_wrap' => '%3$s', 'theme_location' => 'primary' ) );

Even this question is quite old, I want to add a working solution. I found this question while searching for exactly the same, but the answer from Mark just removes the container not the ul or li tags of wp_nav_menu.
Remove all <ul> and <li> tags from wp_nav_menu:
function remove_wp_nav_menu_ul($menu){
return preg_replace( array( '#^<ul[^>]*>#', '#</ul>$#', '#^<li[^>]*>#', '#</li>$#' ), '', $menu );
}
add_filter( 'wp_nav_menu', 'remove_wp_nav_menu_ul' );
Just place that in the function.php of your theme. But before doing so, always consider to solve this with CSS before.

Below code in functions.php
function remove_wp_ul($menu){return preg_replace( array( '#^<ul[^>]*>#', '#</ul>$#', '#^<li[^>]*>#', '#</li>$#' ), '', $menu );}
add_filter( 'wp_nav_menu', 'remove_wp_ul' );
Inside header.php, write the following code:
wp_nav_menu(array('menu' => 'mymenu','container' => false,)); ?>

Related

How to display custom links in WordPress with wp_nav_menu?

I'm creating an one-page custom theme. I'm struggling with a custom menu, because I want to display custom links.
I've registered menu in functions.php file
function register_my_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' ),
)
);
}
add_action( 'init', 'register_my_menus' );
Then, I've displayed in header.php file like this:
<?php wp_nav_menu( array(
'theme_location' => 'top-menu',
'container' => 'ul',
'menu_class'=> 'd-flex main-menu'
) );
?>
I've added custom classes for ul tag, and that is okay. Navigation works but just for pages. When I create a page, a link for that page shows up in navigation. However, after creating custom links they don't appear in navigation.
I'm searching the Stachoverflow for some quiet time, but without success. How to resolve a described issue? Do you have an idea?
Thank you for your time.
You have register header menu with header-menu key and trying to get it by key of top-menu which is not possible. You have to use the header-menu key to add and get a header menu. we have updated the code. you can use this code.
<?php
wp_nav_menu( array(
'theme_location' => 'header-menu',
'container' => 'ul',
'menu_class'=> 'd-flex main-menu'
) );
?>

Unable to get wordpress register_nav_menus working

I am building my 1st theme, and got stucked with showing menu option on admin's screen under appearance. I refered various support thread but none of the solution is working for me.
Codes in function.php
<?php
//Create Nav menu
if (function_exists(register_nav_menus)) {
register_nav_menus( array('primary' => 'Header Navigation') );
}
?>
Codes in header.php
<?php
wp_nav_menu( array( 'container_class' => 'main-nav' , 'container'=>'nav') );
?>
I am executing this on localserver and wordpress version 4.0
image of header.php
http://i.imgur.com/ziPGH2G.png
image of function.php
http://i.imgur.com/ica5VJx.png
Thats all of it.
Please help me out.
First rename function.php to functions.php , note the the "s". http://codex.wordpress.org/Functions_File_Explained
Second try registering the menu inside a hook like init or after_theme_setup
add_action( 'after_setup_theme', 'register_my_menu' );
function register_my_menu() {
register_nav_menu( 'primary', 'Header Navigation' );
}
You're missing some arguments (and a comma in your array). You need to pass in a menu name:
$args = array(
'menu' => 'primary',
'container' => 'nav',
'container_class' => 'main-nav',
);
wp_nav_menu( $args );
Also be aware that this menu must exist in the admin, and must be assigned to the menu location you just created.

Insert another menu into WordPress... not working at all?

I am following this guide to "Add additional support for menus in your theme":
http://codex.wordpress.org/Navigation_Menus
I followed all of the steps, but this is the result:
http://puu.sh/30bMt.png
So, it's "inserting a menu" where I told it to.... however the items on the menu do not match up with what I have in the WordPress back-end, seen here...
http://puu.sh/30bQd.png
I only inserted 4 items into the menu "Test"... but it's displaying every page, instead of the 4 items I want.
I've attempted to do research to figure out what's going on to no avail; does anybody have any insight as to why this is acting funky?
Code where I'm "registering" the additional menu support... (themes function.php):
function register_my_menus() {
register_nav_menus(
array(
'header-menu' => __( 'Header Menu' )
)
);
}
add_action( 'init', 'register_my_menus' );
Code where I'm inserting the "Header Menu" itself... (themes header.php):
<?php
wp_nav_menu( array( 'theme_location' => 'extra-menu', 'container_class' =>'my_extra_menu_class' ) );
?>
If you are trying to call 'Header Menu' then the code in your header.php should look like this:
<?php wp_nav_menu(array('theme_location' => 'header-menu', 'menu_class' => 'my_extra_menu_class')); ?>
I'm not sure where you got 'extra-menu' from but WordPress doesn't know what that is since you didn't declare that in your register_my_menus function.
I hope that helps.
Here's an example of how I've implemented multiple menus in my WordPress install:
// Register Extra Menus
function new_register_menus() {
register_nav_menus(array('Products'=>'Products Nav', 'Support'=>'Support Nav', 'Company'=>'Company Nav' , 'Footer'=>'Footer Nav'));
}
add_action( 'init' , 'new_register_menus' );
//Code in my footer.php
<?php wp_nav_menu(array('theme_location' => 'Footer', 'menu_class' => 'nav')); ?>

working with wp_nav_menu on wordpress

I'm having an issue working with wp_nav_menu, I'm trying to create my own Theme for WP, now i've putted that code into my functions.php file,
function register_my_menu() {
register_nav_menu('header-menu',__( 'Header Menu' ));
}
add_action( 'init', 'register_my_menu' );
as the guide said, and now when I'm trying to combine it into my design, the paramters I pass in the wp_nav_menu function doesn't really do anything, and I dont really understand why, I tried to play with it but it doesnt seem like something gets changed.
`
wp_nav_menu( array( 'items_wrap' => '<ul id="danny" class="danny">%3$s</ul>','theme_location' => 'header-menu' ) );
`
it doesnt metter what I do, what I add as a paramter the output stays as it is, anyone has anyidea? am I missing something?
thanks!
Why not instead of registering your menu, you just use 'menu' parameter like this:
wp_nav_menu( array( 'items_wrap' => '<ul class="%2$s danny" id="danny">%3$s</ul>','menu' => 'header-menu' ) );
Take another peek at the Codex: http://codex.wordpress.org/Function_Reference/wp_nav_menu
Instead of passing that markup try the parameters for menu_class and menu_id. for example:
<?php wp_nav_menu( array( 'theme_location' => 'header-menu', 'menu_class' => 'danny', 'menu_id' => 'danny' ) ); ?>

Wordpress - Adding class to the href in the using wp_nav_menu

I was wondering if its possible to add a class for the current page to the href tag instead of the li tag that wordpress uses by default.
By menu arguments are as follows:
<?php wp_nav_menu( array(
'theme_location' => 'main-menu',
'container' => '',
'menu_class' => '',
'menu_id' => 'nav'
) ); ?>
Cheers,
why do you want to do this? you can access the A in css using something like this:
#nav li.current-menu-item a {
text-decoration:underline;
}
what exactly do you want to achieve?

Resources