Well, you’re getting error, because your code is not correct… There is syntax error in this line (You combine string and PHP code in there…):
$items .= '<li class="menu-item">echo do_shortcode( '[contact-form-7 id="1323" title="Newsletter"]' );</li>';
It should look like this:
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;
}
Related Posts:
- WordPress menu deletes when trying to add a hook
- Adding first / last CSS classes to menus
- how to put the logo in the center of other items in the navigation bar
- Hide a menu-item and its submenus and display a ‘Log in’ link if the user is logged out
- Can we have a php “page” without a WordPress “page”?
- How to add active class to custom menu using while loop and wp_list_pages
- How to return a string that has a variable inside in a shortcode?
- Passing a shortcode attribute to a sub-function
- wp_delete_auto_drafts() deletes links in menus
- Adding Image Count to Multigallery
- Custom plugin issue when trying to use the shortcode twice on a page [closed]
- Logout and redirect using the WP Menu
- Creating new menu item
- Programmatically create menu with custom link
- Custom Loop through category menu to include sub categories
- Nested shortCode functions in the functions.php file
- get_page_by_title with an apostrophe in variable
- How can I get content inside one shortcode to another shortcode?
- is_page “range” for if statement?
- Add itemprop Schema.org Markup to li Elements in wp_nav_menu
- Use WP_Query in shortcode
- create a select input with menus created on a custom options page
- Different loop output every x posts in custom post type
- Showing a different gallery in a seperate post
- Add data attribute to each li in menu
- How to exclude category ID from Looper in WordPress
- Add a specific part of current category page url to shortcode
- Calculating a large number of MYSQL queries as customshort codes, slow
- WordPress Shortcodes.. printf is outputting a random number… Can’t figure out WHY?
- Remove metabox from WordPress menu editor page?
- How can I dynamically update the class in my shortcode?
- Secondary navigation menu on one page
- Remove class in nav_menu_link_attibutes filter
- Displaying recent posts on static page with template-part via shortcode
- WordPress Quick Question . How to Get Parent Link in Submenu in My Code
- How to Reference/Echo Variable from Another PHP Function
- Replace shortcode in substring
- Detecting classes, adding widgets, and adding divs in with a Nav Walker
- Adding PHP in the menu
- displaying content that includes shortcodes within an echo
- List taxonomy term slugs within shortcode (do_shortcode)
- Display Data in Table from External Database in WP using Shortcodes
- New walker for walker_nav_menu to change inside container data
- Add data-id attribute to child page links
- Capitalize Shortcode Value on Output
- Why is my str_replace not working on short code submitted by front-end?
- Shortcode not staying inside div tag
- Shortcode to pull posts
- How to return a string that has a jQuery and Ajax inside in a shortcode?
- Notice: Trying to get property of non-object
- Shortcode function doesnt work without caption
- Adding Additional Variables on Menus Page
- Nav-Menu not showing up
- Create special button on WP Tiny MCE Posts Editor for Shortcodes
- Change Spaces to Dashes?
- Class for Selected Menu using wp_nav_menu
- Hard-coding a shortcode as the last menu item in primary navigation?
- Nav Walker that shows only children and siblings of top level parent menu item
- how to changes mobile menu toggle breakpoint in WordPress
- How to display already created menus via php?
- using shortcodes inside gravity forms
- Display logged in user name and lastname on page
- Featured image in menu wordpres
- Replace background image with post thumbnail in shortcode
- Conditional formatting on data fetched from MYSQL
- Having trouble creating two shortcodes, one for logged in user and one for visitors
- How to use Contact Form 7 shortcode value in a page?
- How to let mobile navigation menu close when link is clicked?
- Display current user metadata on WordPress page
- Add Shortcode to ::before class
- Reload page with a different shortcode when a user selects from a dropdown
- How Can I Display the Last Modified Date for User Profiles on WordPress?
- PHP warning with code for nav menu walker [duplicate]
- Add element after navigation element title don’t works like I expect
- String replace for Login/Logout concatenation problem in menu
- Shortcode’s output to use as other shortcode’s parameter
- Show products per shortcode
- How to create a sub-page of sub-page?
- Add two or multiple functions in WordPress Post or Page
- Shortcode Works for Logged in Users but Not Working for Guest
- perform mathematical operation on shortcode
- Update same content in multiple posts at once?
- Adding button to wordpress menu
- problem multisite with blog id
- wp_nav_menu prints children with parent name
- Overwriting a Shortcode
- How to get the count for each taxonomy term
- WP_Nav Highlight Parent Issue
- if is_home(), change class of menu-item-225 of wp_nav_menu
- Change order that the menu is generated with wp_list_pages
- I am extending Walker_Nav_Menu: How can I get the number of children elements of the current item?
- Whats wrong with my code? Need To add String to shortcode? [closed]
- A next page function with shortcode?
- using a shortcode in a hyperlink
- Display total count of products in orders of a specific order status
- why css file not link?how to create permalink?
- How to add different menu items on different menus?
- Show Login Errors In WordPress/Elementor (Code “works”, but breaks site)
- Nav menù doesn’t display selected pages
- Shortcode Displays 2 times