Last active
June 6, 2021 12:10
-
-
Save galengidman/ef6f1f42aa67e06b6d69 to your computer and use it in GitHub Desktop.
Adding Static Menu Items to wp_nav_menu()
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 | |
function my_nav_wrap() { | |
// default value of 'items_wrap' is <ul id="%1$s" class="%2$s">%3$s</ul>' | |
// open the <ul>, set 'menu_class' and 'menu_id' values | |
$wrap = '<ul id="%1$s" class="%2$s">'; | |
// get nav items as configured in /wp-admin/ | |
$wrap .= '%3$s'; | |
// the static link | |
$wrap .= '<li class="my-static-link"><a href="#">My Static Link</a></li>'; | |
// close the <ul> | |
$wrap .= '</ul>'; | |
// return the result | |
return $wrap; | |
} |
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
<nav> | |
<?php wp_nav_menu(array( | |
'theme_location' => 'my_menu_location', | |
'items_wrap' => my_nav_wrap() | |
)); ?> | |
</nav> |
How can I add class to a tag?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
+1 Thank you.