![]() This code tells WordPress that we will use shortcodes in WordPress menu items. add_filter('wp_nav_menu_items', 'do_shortcode') You can put these codes in your own custom plugin.įirst, open the functions.php file of your template and put the following codes in it. This is actually adding the Elementor page builder Template to the menu through the WordPress shortcode.įor this, all the codes will be placed in the template file. In this section, you will learn how to implement this menu using a shortcode. If you have used the Woodmart template, you will notice that this template uses page builders such as Elementor to design mega menus. You may have seen mega menus on many sites and wondered how these menus are created. Adding a shortcode to the WordPress navigation menu This example also adds the main-menu-class class to the menu. If you look at the code above, you will notice that the menu parameter contains the name of the menu, which is sent to the shortcode and is placed in the menu section inside the shortcode, and the wp_nav_menu function displays the menu whose name is “Main Menu”.Īny parameters you pass to the shortcode will be placed inside the function. Open your post and add the following shortcode to display “Main Menu” items inside your post. You can display the “Main Menu” by adding the following shortcode. For example, suppose you have a menu called “Main Menu” and you want to display this menu inside your post. Copy that menu name from there and add it to your shortcode. Now we can use this WordPress shortcode anywhere on the website to display the desired menu. Just go to Appearance > Menus and find the menu name as shown in the image below. function hs_list_menu($atts, $content = null)Īdd_shortcode('listmenu', 'hs_list_menu') In this section, we use the possibility of creating a shortcode in WordPress and this function to create our custom shortcode to display a menu. The first thing you need to do is enable the shortcode option itself as without it the shortcode will not be active and you will just see text displayed on your. playlist allows you to display collection of audio or video files. video allows you to embed and play video files. From here, you can add new language switchers to the menu or a widget, or you can edit the default language switcher in the footer. To add and customize language switchers to these specific areas, go to WPML Languages in the WordPress dashboard. audio allows you to embed and play audio files. Add a Language Switcher to a Menu, Footer, or Widget. gallery allows you to show image galleries. The wp_nav_menu function is used to display the menu in the template. By default, WordPress includes the following shortcodes: caption allows you to wrap captions around content. Create a shortcode to display the menu on the WordPress page In this case, we can easily add the shortcode of the designed menu to the desired menu in the list section so that it can be displayed in that section. You can use this article to display your desired menu anywhere on the WordPress website using a shortcode, and you can also put any shortcode you want in your menu item to be displayed in the navigation menu.įor example, we created the menu using the Elementor page builder, and we want to display that menu in the navigation section of the site as a sub-menu (mega menu). In the following, we will explain how to add a shortcode to the page or post and display the menu inside it, and how to add a shortcode inside the menu like submenus and its development in WordPress. This is a great way to save time and make your website look more professional.įrom WordPress version 3 onwards, we can use the wp_nav_menu function to create and display WordPress navigation menus. Create a new Custom Link menu item and position the item within the menu where you would like the shortcode to be displayed. This can be used to quickly add a navigation menu to any page or post without having to manually code the menu. * WP_Post The menu items with any placeholders properly filled in.A WordPress menu shortcode is a small piece of code that can be used to create dynamic menus on your website. * WP_Post $menu_items All of the nave menu items, sorted for display. * Filters all menu item URLs for a #placeholder#. With the following code in functions.php, you can create a custom menu item with the URL #profile_link#, and it will replace that with your shortcode. ![]() To use the shortcode just place listmenu menuSitemap into your post and that's it (replace Sitemap with the id, slug, or name of the menu you want to list). But you can use placeholders like this: #profile_link#. To install the shortcode just place this code inside the functions. You can't use shortcodes directly in the menu URL on the menu page, because the brackets get stripped out.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |