If you’re just trying to replace <ul...>
and </ul>
with <menu...>
and </menu>
in the generated HTML, you can use the wp_nav_menu
filter:
add_filter( 'wp_nav_menu', 'wpse_426932_menu_fix' );
/**
* Fixes the menu HTML to use <menu> instead of <ul>.
*
* @param string $html The menu HTML.
* @return string The fixed menu HTML.
*/
function wpcs_426932_menu_fix( $html ) {
$html = str_replace(
array( '<ul', '</ul>' ),
array( '<menu', '</menu>' ),
$html
);
return $html;
}
You can add this code to your active theme’s functions.php
file or you can make it into a simple plugin. (I tend to prefer the plugin route, because that way it keeps on working even if you change themes.)
Note: This is a very simple string replacement. If you need something more complex, you might need to use preg_replace()
.