So I'm adding descriptions to my site's main menus. Checked the box, added the text. Dropped in a custom walker in functions.php. Dropped in a wp_nav_menu call in header.php to call the custom walker. Added text to the descriptions.
All good... but then I decided I wanted to add breaks via HTML... Dammit they're being stripped out. Oh, right, I need to turn off that filter. So I do, via the correct line in functions.php. ONly, it doesn't work. The HTML is still being stripped.
Before I go on, here's the walker I'm using with the filter removal line after it:
#new walker to enable description text under menu items.
class description_walker extends Walker_Nav_Menu
{
function start_el(&$output, $item, $depth, $args)
{
global $wp_query;
$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
$class_names = $value = '';
$classes = empty( $item->classes ) ? array() : (array) $item->classes;
$class_names = join( ' ', apply_filters( 'nav_menu_css_class', array_filter( $classes ), $item ) );
$class_names = ' class="'. esc_attr( $class_names ) . '"';
$output .= $indent . '<li id="menu-item-'. $item->ID . '"' . $value . $class_names .'>';
$attributes = ! empty( $item->attr_title ) ? ' title="' . esc_attr( $item->attr_title ) .'"' : '';
$attributes .= ! empty( $item->target ) ? ' target="' . esc_attr( $item->target ) .'"' : '';
$attributes .= ! empty( $item->xfn ) ? ' rel="' . esc_attr( $item->xfn ) .'"' : '';
$attributes .= ! empty( $item->url ) ? ' href="' . esc_attr( $item->url ) .'"' : '';
$description = ! empty( $item->description ) ? '<p class="menu_description">'.esc_attr( $item->description ).'</p>' : '';
if($depth != 0)
{
$description = $append = $prepend = "";
}
$item_output = $args->before;
$item_output .= '<a'. $attributes .'>';
$item_output .= $args->link_before .$prepend.apply_filters( 'the_title', $item->title, $item->ID ).$append;
$item_output .= $description.$args->link_after;
$item_output .= '</a>';
$item_output .= $args->after;
$output .= apply_filters( 'walker_nav_menu_start_el', $item_output, $item, $depth, $args );
}
}
## Function to stop HTML removal from menu descriptions
remove_filter('nav_menu_description', 'strip_tags');
More info: The HTML is recorded in the database, so it's present there... just not on output. This is in Wordpress 3.3. For clarity, here's the code that calls the menu in header.php:
<?php
wp_nav_menu( array(
'theme_location' => 'primary',
'depth' => 0,
'walker' => new description_walker())
);
?>
I have that sinking feeling I'm missing something basic and just need a new pair of eyes on this... any ideas?
$depth != 0
conditional block.<p>Line 1</p> <p>Line 2</p> <p>Line3</p>
in the generated code I get:Line 1 Line 2 Line3
just as you'd expect if the strip_tags filter was active. Since I added a remove_filter call in function.php, it shouldn't be. Same thing happens with<br />
tags.