nav_menu_link_attributes filter adds ending slash

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

nav_menu_link_attributes filter adds ending slash

Thomas Belknap
I'm using the nav_menu_link_attributes filter to change the behavior of a
specific post type. The first thing I noticed was that, in contrast to what
the documentation says on this, $item refers to the *menu* item, not to the
object to which it is linked.

But beyond that, it seems that despite the fact that I'm replacing the
'href' attribute of the link, something somewhere is adding a trailing
slash, which is messing up what I'm doing. Here's the code I'm using:

function nav_menu_panel_item( $attrs, $item, $args ) {
if( stristr($attrs['href'], 'hn_panel') ) :
preg_match( '|([^/]+)/?$|', $attrs['href'], $target );
$attrs['href'] = '#' . $target[0];
$attrs['class'] = stristr( $attrs['class'], 'smoothscroll' ) ?
$attrs['class'] : $attrs['class'] . ' smoothscroll';
return $attrs;
add_filter( 'nav_menu_link_attributes', array( &$this,
'nav_menu_panel_item' ), 10, 3 );

As you can see, the point is to convert the "hn_panel" post type menu items
into on-page anchor navigation. But by adding the trailing slash, WP is
preventing this function from working.

Is there another filter that I'm missing? I've set the priority from 1 to
100 and back to 10, but that doesn't seem to help.


Tom Belknap
Owner/Editor, DragonFlyEye.Net
Freelance writer
Join me:

   - *Inbox:*
   - *Web*:
   - *Facebook*:
   - *Twitter*:
   - *Google*:
wp-hackers mailing list
[hidden email]