create a mega menu with 3 columns and heading of each column will be Title 1, Title 2, Title 3

WPTurbo » Snippets » create a mega menu with 3 columns and heading of each column will be Title 1, Title 2, Title 3
0

Created with:

Visibility: 

public

Creator: SupportVCAN

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project
					<?php


namespace WPTurbo;

function wpturbo_register_mega_menu() {
    register_nav_menus( [
        'mega_menu' => __( 'Mega Menu', 'wpturbo' ),
    ] );
}
add_action( 'after_setup_theme', 'WPTurbowpturbo_register_mega_menu' );

function wpturbo_mega_menu() {
    $menu_items = wp_nav_menu( [
        'theme_location' => 'mega_menu',
        'items_wrap' => '%3$s',
        'echo' => false,
    ] );

    if ( ! empty( $menu_items ) ) {
        echo '<div class="mega-menu">';
        echo '<div class="column">';
        echo '<h3>Title 1</h3>';
        echo $menu_items; // This will output your menu items under Title 1
        echo '</div>';
        echo '<div class="column">';
        echo '<h3>Title 2</h3>';
        echo $menu_items; // This will output your menu items under Title 2
        echo '</div>';
        echo '<div class="column">';
        echo '<h3>Title 3</h3>';
        echo $menu_items; // This will output your menu items under Title 3
        echo '</div>';
        echo '</div>';
    }
}
add_action( 'wp_footer', 'WPTurbowpturbo_mega_menu' );
				

Remember to style the mega menu using CSS to ensure the columns display correctly according to your theme's design.

Register an account to save your snippets or go Pro to get more features.