Does anyone have a solution for converting a Webflow navbar code that uses <a> elements to a WordPress theme that uses ul or li elements for the menu? I've been trying for 2 days and need a solution without having to update my CSS stylesheet. Thank you!

TL;DR
  • Create a custom WalkerNavMenu class to override default WordPress menu output, removing <ul> and <li> tags and outputting only <a> elements.  
  • Register and apply this custom walker in wpnavmenu(), ensuring the correct Webflow-style classes are added to each <a> tag for styling consistency.

You want to convert a Webflow navbar built with <a> elements into a structure compatible with WordPress menus, which typically use nested <ul> and <li> elements—without modifying your CSS. This requires adapting the WordPress menu walker output to match Webflow's structure rather than restructuring your CSS.

1. Understand the Webflow vs WordPress Menu Structure

  • Webflow navbars often place <a> tags directly inside a container (e.g., a div), like:  

  <div class="nav-links"><a href="#">Home</a></div>

  • WordPress menus normally output a structure like:  

  <ul><li><a href="#">Home</a></li></ul>

2. Use a Custom Walker in WordPress

  • WordPress allows developers to override the default menu HTML using a custom WalkerNavMenu class.
  • Goal: Modify the walker so that it skips the <ul> and <li> tags, outputting direct <a> tags inside a container—matching Webflow’s format.

3. Sample Custom Walker Approach

  • In your theme’s functions.php, create a custom walker:
  • Extend WalkerNavMenu and override the start_el() and end_el() methods.
  • Omit the <li> tags and output only the <a> tag with the correct classes.
  • Optionally, override start_lvl() and end_lvl() to skip <ul> wrapping if needed.

4. Register and Use the Custom Walker

  • In your theme template where you use wpnavmenu(), pass your custom walker:

  ```php

  wpnavmenu(array(

    'theme_location' => 'primary',

    'walker' => new YourCustomWalker(),

    'container' => false, // optional if you don’t want extra divs

    'menu_class' => 'nav-links' // match Webflow’s class

  ));

  ```

5. Match Webflow Classes Without Changing CSS

  • Make sure your custom walker applies the correct class names to the <a> tags, matching your styles from Webflow.
  • Example: Add class="nav-link" to each <a> if that's what your Webflow uses.

6. Optional: Use Filters If Walker Feels Too Complex

  • If building a custom walker sounds too involved, consider using the wpnavmenu_items filter to manipulate the menu HTML string before rendering—but this gives less control and should be used cautiously.

Summary

To display WordPress menus with only <a> tags (like Webflow), create a custom walker that removes WordPress’s default <ul> and <li> markup and outputs only <a> tags with correct classes. This avoids CSS changes and aligns with Webflow’s structure.

Rate this answer

Other Webflow Questions