Created
June 15, 2020 23:15
-
-
Save MogulChris/7e7deb4de952fb6de1bf9f1400c1bf8c to your computer and use it in GitHub Desktop.
Output HTML after WordPress menu items
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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