• Resolved NF Graphic Design

    (@nf-graphic-design)


    I am trying to put a simple 1 field contact form field into the menu, I got this code to work for text, but not sure how I can get it to work with shortcode?

    Working code:

    add_filter( 'wp_nav_menu_items', 'your_custom_menu_item', 8, 2 );
    function your_custom_menu_item ( $items, $args ) {
    if( $args->theme_location == 'primary')  {
        $items .= '<li class="menu-item">Text goes here</li>';
    }
    return $items;
    }

    When I add shortcode like below, I get an error:

    add_filter( 'wp_nav_menu_items', 'your_custom_menu_item', 8, 2 );
    function your_custom_menu_item ( $items, $args ) {
    if( $args->theme_location == 'primary')  {
        $items .= '<li class="menu-item">echo do_shortcode( '[contact-form-7 id="1323" title="Newsletter"]' );</li>';
    }
    return $items;
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter NF Graphic Design

    (@nf-graphic-design)

    Just incase anyone else is looking to do this, here is the correct code:

    add_filter( 'wp_nav_menu_items', 'your_custom_menu_item', 8, 2 );
    function your_custom_menu_item ( $items, $args ) {
        if( $args->theme_location == 'primary')  {
            $items .= '<li class="menu-item">'. do_shortcode( '[contact-form-7 id="1323" title="Newsletter"]' ) .'</li>';
        }
        return $items;
    }
    Thread Starter NF Graphic Design

    (@nf-graphic-design)

    solved

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Insert custom object into wordpress menu’ is closed to new replies.