Monday , 29 May 2017
Home » Wordpress » [WordPress] Remove UL LI from wp_nav_menu
[WordPress] Remove UL LI from wp_nav_menu

[WordPress] Remove UL LI from wp_nav_menu

Hello Friends,

I was working with WordPress since long time and I am becoming familiar with more and more built in functions and usage of WordPress functions. Really, WordPress makes life more easier than we think. As i developer, you should know argument of functions and how to make it more and more flexible. I was using wp_nav_menu function for footer menu and I would like to remove div tags, ul tags and li tags. I just need to put <a> tags.

If you do not need ul tags in wp_nav_menu function, you just need to pass below argument in wp_nav_menu function’s parameter.

 '%3$s'

Just pass above argument and you will get output with out ul tags.

Now you want remove li tags. WordPress does not have anything and they will return li tags in output. so we need to remove li tags manually using our code. Look at below code.

$args = array(
  'echo'            => false,
  'items_wrap'      => '%3$s',
);
echo strip_tags(wp_nav_menu( $args), '<a>' );

Here, we are passing false to echo argument so it will give us the output instead of direct print. Once we get the output, we have passed it in strip_tags function to remove all html tags but passing <a> which is exceptional. so other than <a>, we have li tags which will be removed. That’s it.

      
Plugin by: PHP Freelancer

About Rakshit Patel

I am PHP Freelancer, Rakshit Patel working as PHP Programmer India. I have developed this site to share my knowledge, thoughts and experience during the development of projects. We are group of developers working together. If you want to hire us for any PHP related work, you can reach me via Email, Phone or Chat.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

Notify me of followup comments via e-mail. You can also subscribe without commenting.