Skip to content

Instantly share code, notes, and snippets.

@MogulChris
Created June 15, 2020 23:15
Show Gist options
  • Save MogulChris/7e7deb4de952fb6de1bf9f1400c1bf8c to your computer and use it in GitHub Desktop.
Save MogulChris/7e7deb4de952fb6de1bf9f1400c1bf8c to your computer and use it in GitHub Desktop.
Output HTML after WordPress menu items
<?php
//Use nav_menu_item_args hook to add extra HTML to a specific menu item. It will appear inside the <li>
//See $item and $args for other things you can inspect and modify
function mytheme_nav_menu_item_args($args,$item,$depth){
//print_r($item);
//print_r($args)
$args->after = '';
if($item->url == '#custom'){ //only output our HTML when we find a specific link
$html = '<p>Custom html</p>';
$args->after = $html;
}
return $args;
}
add_filter('nav_menu_item_args','mytheme_nav_menu_item_args',10,3);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment