menu


WordPress how to add all menus into post

1. Use a shortcode to display all menus

You can create a custom shortcode that lists all registered menus, then insert that shortcode into any post.

Here’s a simple way to do it:

Step 1: Add this to your theme’s functions.php file:

function list_all_menus_shortcode() {
    $menus = wp_get_nav_menus();
    $output = '';

    if (!empty($menus)) {
        foreach ($menus as $menu) {
            $menu_items = wp_get_nav_menu_items($menu->term_id);

            if (!empty($menu_items)) {
                $output .= '<h2>' . esc_html($menu->name) . '</h2>';
                $output .= '<ul>';

                foreach ($menu_items as $item) {
                    $output .= '<li><a href="' . esc_url($item->url) . '">' . esc_html($item->title) . '</a></li>';
                }

                $output .= '</ul>';
            }
        }
    } else {
        $output = '<p>No menus found.</p>';
    }

    return $output;
}
add_shortcode('all_menus', 'list_all_menus_shortcode');


Step 2: Use [all_menus] shortcode inside your post content.

✅ Now when you insert [all_menus] into any post or page, it will automatically display all menus with their items.


2. Use a shortcode to print all menu names quoted and separated by a comma

function print_all_menu_names_shortcode() {
    $menus = wp_get_nav_menus();
    $names = [];

    if (!empty($menus)) {
        foreach ($menus as $menu) {
            $names[] = '"' . esc_html($menu->name) . '"';
        }
        return implode(', ', $names);
    } else {
        return 'No menus found.';
    }
}
add_shortcode('print_menu_names', 'print_all_menu_names_shortcode');


How to use:

  • Add the code to your theme’s functions.php or your custom plugin.
  • Then just put this shortcode wherever you want the menu names to appear:
[print_menu_names]

✅ This will output something like:

"Main Menu", "Footer Menu", "Sidebar Menu"


3. Use a shortcode to print all menus in a custom sort

Each WordPress menu has a unique ID ($menu->term_id) and a name ($menu->name).
You can identify them either by their ID or by their name.

Then, you manually set the order you want.


Here’s how you can do it:

Update the shortcode function like this:

function list_all_menus_shortcode() {
    $menus = wp_get_nav_menus();
    $output = '';

    if (!empty($menus)) {
        // Step 1: Define the hard-coded order you want (by menu ID or menu name)
        $custom_order = [
            'Main Menu',     // by name
            'Footer Menu',
            'Sidebar Menu',
        ];
        
        // Step 2: Reorder the menus according to your custom order
        $ordered_menus = [];
        foreach ($custom_order as $name) {
            foreach ($menus as $menu) {
                if ($menu->name === $name) { // use $menu->term_id if you want to match by ID
                    $ordered_menus[] = $menu;
                    break;
                }
            }
        }

        foreach ($ordered_menus as $menu) {
            $menu_items = wp_get_nav_menu_items($menu->term_id);

            if (!empty($menu_items)) {
                $output .= '<h2>' . esc_html($menu->name) . '</h2>';
                $output .= '<ul>';

                foreach ($menu_items as $item) {
                    $output .= '<li><a href="' . esc_url($item->url) . '">' . esc_html($item->title) . '</a></li>';
                }

                $output .= '</ul>';
            }
        }
    } else {
        $output = '<p>No menus found.</p>';
    }

    return $output;
}
add_shortcode('all_menus', 'list_all_menus_shortcode');


Important notes:

  • Replace "Main Menu", "Footer Menu", etc., in $custom_order with your real menu names.
  • Alternatively, you can match by term_id instead of name if you prefer.

👉 To find your menu IDs easily, go to:
WordPress Dashboard → Appearance → Menus, then hover over a menu — you’ll see a URL like:

/wp-admin/nav-menus.php?action=edit&amp;menu=45

Here, menu=45 means term_id = 45.

If you want to match by ID, change the matching line:

if ($menu->term_id == $id) {

instead of name matching.

A contemporary logo for a Cypriot ethical hacking group, combining traditional and digital motifs. The logo includes an abstract representation of a castle tower, signifying defense and strategy, with a circuit board pattern. The Cyprus flag is cleverly integrated into the tower design. Above the tower flies a stylized eagle, representing vigilance in cybersecurity. The group's initials, 'CEH', are interwoven into the base of the tower in a futuristic typeface.

Android USSD Code to access hidden testing menu

The following USSD code once dialed and called as a phone number, will give you access to a hidden testing menu for Android devices.

*#*#4636#*#*

Unstructured Supplementary Service Data (USSD), sometimes referred to as “Quick Codes” or “Feature codes,” is a communications protocol used by GSM cellular telephones to communicate with the mobile network operator’s computers. USSD can be used for WAP browsing, prepaid callback service, mobile-money services, location-based content services, menu-based information services, and as part of configuring the phone on the network.

From: https://en.wikipedia.org/wiki/Unstructured_Supplementary_Service_Data

WPML: How to add the Languages’s list in a WordPress menu

The code in this article can be used to create a WPML language switcher that will be attached at the bottom of a specific WordPress menu. Each Language will be a sub-menu item of a new menu item named Languages.

Menu Languages Options

You should add this code to your theme’s functions.php file. It is highly recommended to add this change to the functions.php of child theme.

Choosing which languages to show

By default, the following code will be showing ALL available languages, including the currently active one. We did that as we only have two languages in our website and it would weird to: (a) have only one sub-menu item in the Languages menu item or (b) remove the Languages menu item and place the inactive language item directly on the menu.

To show only the inactive languages, change the line that contains $showActive = true; to $showActive = false;.

Choosing which menu to show the languages on

To choose the menu on which you want the languages to appear in, you need to set the value of $themeLocation = 'main'; to the theme location that the menu has in your current theme.

For the default WordPress themes (Twenty Sixteen, Twenty Fifteen, etc.) setting the value to primary as follows $themeLocation = 'primary'; will add the languages to the main menu.

For the customizr theme (this also works for the pro version),  setting the value to main as follows $themeLocation = 'main'; will add the languages to the main menu.

For other themes, you need to find the name of the menu you want to append the languages to. To do so change the line $showMenuName = false; to $showMenuName = true;. This will print at the beginning of your menu the location of the menu inside the theme using a <pre> tag. Copy that value to the $themeLocation variable, change the $showMenuName back to $showMenuName = false; and you are done.

Menu Location

/* Add languages menu to main menu */
add_filter('wp_nav_menu_items', 'new_nav_menu_items', 10, 2);
function new_nav_menu_items($items, $args) {
    
    $showActive = true;
    $themeLocation = 'main';
    $showMenuName = false;

    if ($showMenuName) {
        echo "<pre>"; print_r(get_object_vars($args)['theme_location']); echo "</pre>";
    }

    // get languages
    $languages = apply_filters( 'wpml_active_languages', NULL, 'skip_missing=0' );

    if ( $languages && $args->theme_location == $themeLocation) {

        if(!empty($languages)){

            $items = $items . '<br/><li class="menu-item">Languages';
            $items = $items . '<ul class="dropdown-menu">';
            foreach($languages as $l){

                if(!$l['active'] || $showActive){
                    $items = $items . '<li class="menu-item"><a href="' . $l['url'] . '"><img src="' . $l['country_flag_url'] . '" height="12" alt="' . $l['language_code'] . '" width="18" /> ' . $l['native_name'] . '</a></li>';
                }
            }
            $items = $items . '</li></ul>';
        }
    }

    return $items;
}

The above code was generated using the documentation examples of WPML.