[wp-trac] [WordPress Trac] #14040: Prevent empty class attribute in start_el of the Walker_Nav_Menu walker class
WordPress Trac
wp-trac at lists.automattic.com
Tue Jun 22 08:20:03 UTC 2010
#14040: Prevent empty class attribute in start_el of the Walker_Nav_Menu walker
class
--------------------------+-------------------------------------------------
Reporter: jaapjanfrans | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Unassigned
Component: Themes | Version: 3.0
Severity: minor | Keywords: walker, start_el, class attribute
--------------------------+-------------------------------------------------
If you filter the classes of a menu item by adding a filter to the hook
'nav_menu_css_class' and your filter function returns an empty array then
a 'class=' string is still added to the output of the element.
I would like the function to check if the $classes string is empty or not
and decide to add 'class=' + $classes only if $classes is not empty.
Current code:
{{{
$classes = join( ' ', apply_filters( 'nav_menu_css_class', array_filter(
$classes ), $item ) );
$classes = ' class="' . esc_attr( $classes ) . '"';
}}}
possible solution:
{{{
$classes = join( ' ', apply_filters( 'nav_menu_css_class', array_filter(
$classes ), $item ) );
if(!empty($classes))
{
$classes = ' class="' . esc_attr( $classes ) .
'"';
}
else
{
$classes = '';
}
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/14040>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list