MainWP Community

Nested extra menu

Hi all,

I had help last week to create an extra menu thank you @Bogdan

With the code. I made simply copy paste and tweaked the code to create 3 menu items underneath overview in the MainWP menu, my ideal would be one menu heading called Extras that I could place above overview if possible else just underneath, and this one menu have the three submenu pages below. Also if possible, each link launching a new tab:

add_filter( ‘mainwp_main_menu’, ‘mycustom_mainwp_main_menu’, 10, 1 );

function mycustom_mainwp_main_menu( $left_menu ) {

$index = 1;

$sub_menu_before = array_slice( $left_menu[‘mainwp_tab’], 0, $index );

$sub_menu_after = array_splice( $left_menu[‘mainwp_tab’], $index );

$addition_item = array();

$addition_item[] = ‘Google Adwords’;

$addition_item[] = ‘addition-item’;

$addition_item[] = ‘https://ads.google.com/’;

$left_menu[‘mainwp_tab’][] = $addition_item;

$left_menu[‘mainwp_tab’] = array_merge( $left_menu[‘mainwp_tab’], $sub_menu_after );

return $left_menu;

}

add_filter( ‘mainwp_main_menu’, ‘mycustom_mainwp_main_menu2’, 10, 1 );

function mycustom_mainwp_main_menu2( $left_menu ) {

$index = 2;

$sub_menu_before = array_slice( $left_menu[‘mainwp_tab’], 0, $index );

$sub_menu_after = array_splice( $left_menu[‘mainwp_tab’], $index );

$addition_item = array();

$addition_item[] = ‘Google Analytics’;

$addition_item[] = ‘addition-item’;

$addition_item[] = ‘https://analytics.google.com/analytics/web/’;

$left_menu[‘mainwp_tab’][] = $addition_item;

$left_menu[‘mainwp_tab’] = array_merge( $left_menu[‘mainwp_tab’], $sub_menu_after );

return $left_menu;

}

add_filter( ‘mainwp_main_menu’, ‘mycustom_mainwp_main_menu3’, 10, 1 );

function mycustom_mainwp_main_menu3( $left_menu ) {

$index = 3;

$sub_menu_before = array_slice( $left_menu[‘mainwp_tab’], 0, $index );

$sub_menu_after = array_splice( $left_menu[‘mainwp_tab’], $index );

$addition_item = array();

$addition_item[] = ‘Google Search Console’;

$addition_item[] = ‘addition-item’;

$addition_item[] = ‘https://search.google.com/search-console/’;

$left_menu[‘mainwp_tab’][] = $addition_item;

$left_menu[‘mainwp_tab’] = array_merge( $left_menu[‘mainwp_tab’], $sub_menu_after );

return $left_menu;

}

If anyone can help it would be much appreciated.

Thanks

Has anyone achieved anything like this?

Hi Chris, can you please try with something like this:

add_filter( 'mainwp_main_menu', 'mycustom_mainwp_main_menu', 10, 1 );
	function mycustom_mainwp_main_menu( $left_menu ) {
		$index          = 0;
		$sub_menu_after = array_splice( $left_menu['mainwp_tab'], $index );
		 $addition_item             = array();
		 $addition_item[]           = 'Extras';
		 $addition_item[]           = 'extras-item';
		 $addition_item[]           = 'https://ads.google.com/';
		 $left_menu['mainwp_tab'][] = $addition_item;
		$left_menu['mainwp_tab'] = array_merge( $left_menu['mainwp_tab'], $sub_menu_after );
		return $left_menu;
	}
	add_filter( 'mainwp_main_menu_submenu', 'mycustom_mainwp_main_menu_submenu', 10, 1 );
	function mycustom_mainwp_main_menu_submenu( $left_submenu ) {
		$addition_item   = array();
		$addition_item[] = 'Google Adwords';
		$addition_item[] = 'https://ads.google.com/';
		$addition_item[] = '';
		$addition_item[] = '_blank';
		$left_submenu['extras-item'][] = $addition_item;
		$addition_item   = array();
		$addition_item[] = 'Google Analytics';
		$addition_item[] = 'https://analytics.google.com/analytics/web/';
		$addition_item[] = '';
		$addition_item[] = '_blank';
		$left_submenu['extras-item'][] = $addition_item;
		$addition_item = array();
		$addition_item[]  = 'Google Search Console';
		$addition_item[]  = 'https://search.google.com/search-console/';
		 $addition_item[] = '';
		$addition_item[]  = '_blank';
		$left_submenu['extras-item'][] = $addition_item;
		return $left_submenu;
	}
1 Like

Hi Bogdan, it works but it doesn’t open a new window, stay on the same tab… but I think it is a very neat addition to our dashboard to access quickly services like ticketing system or other tools. Thanks, @cad861 for the idea!

Hi @bogdan great :slight_smile: looks exactly as I asked and so thank you. Only thing as @wpexpert has mentioned is it doesn’t open in new tabs, any thoughts. Not much effort to hold shift or CTRL and click but would be cool :slight_smile:

Also no problem @wpexpert I’d suggested a long while back but in truth not sure whether as part of a support ticket or not now. I think two elements, you could use for the left menu and maybe bring the community link and support links over and tidy the top bar and the other could be as a plugin where you simply click to add link for the benefit of the customer. I.e. I know I use certain sites as regularly as MainWP and so for me to define a user menu would be cool.

For me I’m happy now I have this snippet (hopefully with new tab soon) and can keep adding this way but others may like to see as an extension.

Thanks

Yeah, the I talked to the dev team and they said that they added support for “open in new tab” and it’s going to be available in the next version.

1 Like

Thanks Bogdan hadn’t appreciated that was a function of MainWP code.

This certainly is great for now.

Thanks

1 Like