Dropdown Menu – PHP Template Tag Usage Explained

Dropdown menu widget is so easy to use as a widget, but it also supports usage of PHP template tags. Using PHP code to insert the menu, you can easily add menus to your theme as many times as you like. In this post i will give you different code snippets to add the widget to your theme.

[toc type=”regular”]

Default usage

Adding dropdown menu widget using php is so easy. If you are going to add just one menu, things get a lot easier. All you have to do is to insert:

<?php shailan_dropdown_menu( ); ?>

somewhere in your header.php template. This is the default usage. This template tag uses settings page to get the necessary information. So after you add this code, you can easily change your menu options in the Dropdown Menu Widget options page.

Adding pages menu

To add a dropdown menu of your pages, you can use:

<?php shailan_dropdown_menu( array( 'menu' => 'pages' ) ); ?>

code. This snippet will get all the other data from the template tag options page except the menu type.

Adding categories menu

To add categories dropdown, you can use:

<?php shailan_dropdown_menu( array( 'menu' => 'categories' ) ); ?>

code. This snippet will also get all the other data from the template tag options page except the menu type.

Adding a custom menu using php code

To add a custom menu you created you need to set menu variable to either its ID or its name. Here are some examples:

<?php shailan_dropdown_menu( array('menu'=>'Katalog') ); // Adds a custom menu named Katalog ?>

<?php shailan_dropdown_menu( array('menu'=>'439') ); // Adds a custom menu with id 438 ?>

You can add as many as you like. There is no limit on the number of menus you can add.

Full arguments template

If those are not enough for your requirements here is the full arguments list. You can create many different menus using this argument template. Just change the variables as you need:

<?php // SETUP
$args =array(
	'menu' => 'pages',			// Menu type pages | categories | menuID | menu name
	'exclude' => '21,35,438',	// IDs of pages to be excluded
	'login' => true,			// Display login/logout link?
	'admin' => false,			// Show site admin link?
	'vertical' => false,		// Display vertical?
	'home' => true,				// Display home link?
	'align' => 'right',			// Align left | center | right
	'width' => '500'			// Width of menu
shailan_dropdown_menu( $args ); ?>


Dropdown menu widget allows you to easily manage your menus. It automatically generates menu code, effects and even CSS styles. All you need is to add it and then edit your menu as you like. Using template tag’s powers, now you can add multiple dropdown menus to your site, even if you don’t have any sidebars. Here i showed you most common uses of the template tag. I hope you found it useful.

NOTE: If you have any ideas, any points that need improvements, please leave your comment below.

About Shailan.com Staff
Shailan.com is a design blog about WordPress and web design. We usually write about wordpress, plugins, themes, web design resources, php, css, jquery, adsense and more.. If you want to get notified about our posts, be sure to subscribe to our feed or follow us on facebook. You can also subscribe to our mailing list. No spam, we promise.

19 Comments on Dropdown Menu – PHP Template Tag Usage Explained

  1. tanx 4 this plugin :)

  2. I am using the ‘pages’ ) ); ?> tag inside a text widget, and its only showing ‘pages’ ) ); ?>.

    Where am I missing?

  3. I am working with “martable” theme & implemented WooCommerce plugin along with your widget for e-comm website, i want my product categories to be shown in a specific menu item. How can we do that?

1 2

2 Trackbacks & Pingbacks

  1. Custom Dropdown Menu Using WordPress 3 Nav Menus - How to | Shailan
  2. How to change order of menu items - How to | Shailan

Leave a comment

Your email address will not be published.