• Resolved Shane Taylor

    (@propertunity)


    I added the following to functions.php which lets me use shortcodes in menus just fine..

    add_filter('wp_nav_menu_items', 'do_shortcode');

    My issue is that when I add a [shortcode] to the navigation label of a specific menu item, it doesn’t put the [shortcode] to the right of the menu-item like I assumed it would, but instead is placing the shortcode outside of the entire menu-header_menu (all menu items)

    Does anyone know what I am missing? Thanks in advance..

Viewing 2 replies - 1 through 2 (of 2 total)
  • Did you write the shortcode handler?
    A common mistake with shortcode handlers is that they echo the result instead of returning it. That means it ends up in a strange place. The handler should always return a string, with no echo statements.
    Also, I didn’t check, but is that the correct filter to use?

    Thread Starter Shane Taylor

    (@propertunity)

    omg yes I was using ‘echo’ instead of ‘return’

    and yes that filter is what I need for the individual menu-item. At least its working for me..

    that fixed it though. thank you ??

    • This reply was modified 4 years, 11 months ago by Shane Taylor.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘adding [shortcode] to menu-item’ is closed to new replies.