26 05 2011
Non-clickable placeholder in WordPress Navigation Menu
Here is a really simple fix for wordpress 3+ to make non-click-able placeholder sections in a wordpress menu.
This code assumes your wordpress nav menu is called ‘sidebar_menu’.
Your nav menu might be defined in your themes functions.php file like below or you can add it as a widget using the ‘custom menu’ widget.
1 2 3 4 |
register_nav_menus( array( 'sidebar_menu' => 'Sidebar Navigation', )); |
There is a wordpress filter that runs on every menu before it is displayed in the format wp_nav_menu_{MENU_NAME}_items
You will need to add the following code to your themes functions.php file.
1 2 3 4 5 6 7 8 9 |
function my_sidebar_menu_heading($items) { // This removes the hyperlink from menu items in the sidebar that have # as the url // It's a workaround so that menu items in the sidebar can be non-clickable headings. $items = preg_replace( '#<a href="\#">(.*)</a>#', '<span>$1</span>', $items ); return $items; } add_filter( 'wp_nav_menu_sidebar_menu_items', 'my_sidebar_menu_heading' ); |
Remember to change wp_nav_menu_sidebar_menu_items to reflect your menu name, for example if your menu is called main_navigation, the function call would be
1 |
add_filter( 'wp_nav_menu_main_navigation_items', 'my_sidebar_menu_heading' ); |
Automatically add alt tags to wordpress featured images Slow connections with cli tools on Debian squeeze
Just exactly what I needed! Thanks!
[…] the interest of non-clickability, this is the most promising thing I’ve found so far. However, it appears only to be for making the menu items […]