So I have a main menu and secondary menu on my site. I need to add html for my 'live chat' icon and I want to add this to my secondary menu. However, it is not a basic link and contains JavaScript and such. Furthermore, I dont want to just add it to the end of the menu, I want it to be the second last link (link before last).

This is the direction I was going, but of course, I cant merely 'inject' a new link / menu item, because its not a standard format link. I need to insert HTML, so the method below isnt going to work...

Your thoughts?

add_filter('wp_nav_menu_items','add_kayako_secondary_menu', 10, 2);
function add_kayako_secondary_menu( $items, $args ) {
    if( $args->theme_location == 'secondary_nav' ) {
        $menu = wp_get_nav_menu_object( $locations['secondary_nav'] );
        $inserted = '!-- <script>my kayako live chat code</script> -->';

        array_splice( $items, $menu->count-1, 0, $inserted );
  • PS: I am already using a theme that extends the walker nav menu and I dont want to alter it because it will get overwritten each time the theme gets updated. – SupaMonkey Aug 13 '15 at 11:58
  • Ended up just inserting a 'custom link' with a class and writing my own javascript and PHP to do the required work and manipulating the link using the class as a reference. – SupaMonkey Aug 13 '15 at 15:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.