Post Pic

How to create a dropdown menu of tags

In order to display your categories in a dropdown menu, WordPress provide the wp_dropdown_categories() function. But if you want to display your tags in a dropdown as well, there’s no built in function. Let’s use wp_dropdown_categories() and modify it in order to be able to display tags in a dropdown menu.

Simply paste the following code where you want the dropdown menu to be displayed. Note that you can use your own taxonomy: Just modify the code on line 5 according to your needs.

<h2><?php _e('Posts by Tags'); ?></h2>
<form action="<?php bloginfo('url'); ?>/" method="get">
<div>
<?php
$select = wp_dropdown_categories('taxonomy=post_tag&show_option_none=Select tag&show_count=1&orderby=name&echo=0');
$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
echo $select;
?>
<noscript><div><input type="submit" value="View" /></div></noscript>
</div></form>

Thanks to WP Lover for the code!

3 Responses

Aug 21 2012 19:39

Thank you very much, i am new to wordpress and dont have much knowledge about html, etc. I have been searching for this topic since last hour. Thank you again.

Sep 08 2012 14:49

This is a great snippet I just looking for. Now It’s easy to display tags in menu instead of sidebar.

Nov 05 2012 02:18

Hi there, just trying this out, my permalink settings is set to use /%postname%/ which does not work with the above, but when I try the above to default back to categories it works (displays categories in dropdown and goes through once selecting a category from the dropdown). Any suggestions why it might not be working with taxonomy=post_tag (it doe show the tags in a dropdown but once an option is selected it goes to 404?

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required

WP Theme of the week

Sponsored Likebox