Webflow sync, pageviews & more.
NEW

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 walker class in functions.php that overrides WordPress's default menu output to render only <a> tags without <ul> or <li>.
  • Use wp_nav_menu() with 'container' set to false and apply the custom walker to output anchors matching Webflow’s structure.
  • Optionally, disable default WordPress menu classes and IDs using filters.

You're trying to convert a Webflow <a>-based navbar to a WordPress-compatible ul > li > a structure without changing your existing CSS. This is challenging because WordPress menus output an unordered list format by default, while Webflow uses standalone <a> tags. Here’s how to bridge that gap without altering your stylesheet.

1. Use WordPress Walker to Modify Menu Output

  • WordPress uses wp_nav_menu() to render menus.
  • You can use a custom walker class to override the default structure and output only anchor (<a>) tags, similar to Webflow.
  • Since you don’t want to update CSS, the goal is to remove ul and li wrappers in the HTML output.

2. Add a Custom Walker Class to functions.php

  • In your WordPress theme's functions.php, add a custom walker that strips the ul and li tags.

  • Use a stripped-down walker like this:

    ```php
    class Webflow_Nav_Walker extends Walker_Nav_Menu {
    function start_lvl( &$output, $depth = 0, $args = null ) {
    // No

      output
      }

      function end\_lvl( &$output, $depth = 0, $args = null ) {    // No </ul> output}function start\_el( &$output, $item, $depth = 0, $args = null, $id = 0 ) {    $output .= '<a href="' . esc\_attr($item->url) . '" class="nav-link">' . $item->title . '</a>';}function end\_el( &$output, $item, $depth = 0, $args = null ) {    // No </li> or similar output}

      }
      ```

    • Note: Adjust class="nav-link" to match your Webflow class names.

    3. Call the Custom Walker in Your Template

    • In your theme’s header.php or wherever the menu appears, replace your current wp_nav_menu() call with:

      ```php
      wp_nav_menu(array(
      'theme_location' => 'primary',
      'container' => false,
      'walker' => new Webflow_Nav_Walker()
      ));
      ```

    • This outputs only the <a> tags per menu item, matching Webflow’s structure.

    4. Optional: Disable WordPress-Added Classes & IDs

    • Add this filter to prevent unwanted class/id output:

      ```php
      add_filter('nav_menu_item_id', '__return_null');
      add_filter('nav_menu_css_class', '__return_empty_array');
      ```

    Summary

    To make a WordPress menu match Webflow’s <a>-only navbar structure without changing your CSS, use a custom walker class that suppresses <ul> and <li> output and renders only <a> tags. This routes WordPress menus through a structure compatible with your Webflow design.

Rate this answer

Other Webflow Questions