Skip to content

Instantly share code, notes, and snippets.

@kadavre
Last active December 28, 2015 00:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kadavre/7411456 to your computer and use it in GitHub Desktop.
Save kadavre/7411456 to your computer and use it in GitHub Desktop.
Sometimes, you may want to add a cool drop down menu that will show all existing categories in your WordPress site. Here is a simple way of doing it. Copy and paste the code below into the index.php or sidebar.php file.
<form action="<?php bloginfo('url'); ?>/" method="get">
<?php
$select = wp_dropdown_categories('show_option_none=Select category&show_count=1&orderby=name&echo=0');
$select = preg_replace("#<select([^>]*)>#", "<select$1 onchange='return this.form.submit()'>", $select);
echo $select;
?>
<noscript><input type="submit" value="View" /></noscript>
</form>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment