Insert custom object into wordpress menu
-
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)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Insert custom object into wordpress menu’ is closed to new replies.