Skip to content

Instantly share code, notes, and snippets.

@isGabe
Created October 12, 2012 23:50
Show Gist options
  • Save isGabe/3882358 to your computer and use it in GitHub Desktop.
Save isGabe/3882358 to your computer and use it in GitHub Desktop.
WordPress Plugin - Custom Menu widget with link descriptions #snippet #WordPress
<?php
/* Create a new menu like so, or call an existing one. The plugin will add the Description_Walker to it for the widget. */
function sidebar_links() {
// display the wp3 menu if available
wp_nav_menu(array(
'menu' => 'sidebar-links',
'container' => FALSE,
'container_id' => FALSE,
'menu_class' => '',
'menu_id' => FALSE,
'depth' => 1,
));
}
?>
@lingokid
Copy link

Why couldn't I have found this 3 hours ago? Brilliant work. I am going to fork it.

@glendraeger
Copy link

This is excellent. A quick question. I want to allow HTML in the description which I'm doing with this:

remove_filter( 'nav_menu_description', 'strip_tags' );
add_filter( 'wp_setup_nav_menu_item', 'cus_wp_setup_nav_menu_item' );
function cus_wp_setup_nav_menu_item( $menu_item ) {
$menu_item->description = apply_filters( 'nav_menu_description', $menu_item->post_content );
return $menu_item;
}

This works fine except for one thing....when I add the menu item it adds all the content from the post into the description. Easy enough to get rid of and it works fine after that....but not for my clients. I looked all over for solution to this and tried several of my own....:-(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment