Adding jQuery link to Nav
-
I need to add a link to a jQuery function to my main navigation. Something like this:
<a id="myJQueryLink" onclick="return false">MY JQ LINK</a>
I found this nifty code and added it to functions.php:
function add_my_link($items, $args) { $class = 'class="menu-item"'; $homeMenuItem = '<li ' . $class . '>' . $args->before . '<a href=" " id="myJQueryLink" onclick="return false">' . $args->link_before . 'MY JQ LINK' . $args->link_after . '</a>' . $args->after . '</li>'; $items = $homeMenuItem.$items ; return $items; } add_filter( 'wp_nav_menu_items', 'add_my_link', 10, 2 );
It worked great, until I realized I shouldn’t be editing the main theme (twentytwelve). So I created a child theme, updated the parent theme and added the same code to a functions.php file in the child’s directory. Now it doesn’t work.
What am I doing wrong? Is there an easier way to add a link with no href, an onclick and an id to the main navigation?
Thanks,
~gyz
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- The topic ‘Adding jQuery link to Nav’ is closed to new replies.