Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zackeryfretty/0fd750900b2774f56c09714ef7c5980c to your computer and use it in GitHub Desktop.
Save zackeryfretty/0fd750900b2774f56c09714ef7c5980c to your computer and use it in GitHub Desktop.
Useful for completely replacing the markup in the <li></li> on an individual element, useful for doing things like adding a logo in the middle of a menu.
// Replace Menu Item HTML Based on Attribute Title
function zf_replace_menu_item_html($item_output, $args) {
// Change 'main-logo' to match menu items Attribute Title
if($args->attr_title === 'main-logo') {
$item_output = '<div><!-- Your HTML Here --></div>';
}
return $item_output;
}
add_filter( 'walker_nav_menu_start_el', 'zf_replace_menu_item_html', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment