List pages or menu without markup
-
I’m trying to output the pages of my website or a menu but without the
<ul>markup etc.I need it to be output similar to the following:
<nav> <span><a href="#">Testimonials</a></span> <span><a href="#">Get in Touch</a></span> <span><a href="#">Some Additional Page</a></span> </nav>But WordPress automatically wraps everything in a list. Is there a way to do this?
I tried the ‘link_before’ and ‘link_after’ parameters with
wp_nav_menuhowever it still wrapped each item with<li></li> </ul>[Please post code snippets between backticks or use the code button.]
-
Hi pealo86,
I did a little research on this and in order to remove the
- markup you would have to alter the WordPress core files which is not recommended. What are you trying to do that requires the page links to not be in a list?
If you’re trying to create a horizontal navigation bar, you can style that with CSS or even a plugin that will modify the CSS for you.
Hope this helps!
IT can be done by adding a custom walker to the nav menu, you can modify the output however you like
I don’t have any sample code, I just know it’s possible. Searching around for a wp_nav_menu custom walker should get you some examples
Why don’t you just use get_pages() and style the output of each item yourself?
Thanks for the tips.
The custom walker looks like the best way to go however I don’t quite have the time at the minute to get my head around how it works.
I may have to just hardcode the nav into the template for now.
For those who are wondering, I need to change the HTML output as I need / want it to be HTML5 as opposed to just a standard XHTML list.
@daluxe Hadn’t thought of using ‘get_pages()’, it’s proving a useful substitute!
Thanks
The topic ‘List pages or menu without markup’ is closed to new replies.