Skip to content

Instantly share code, notes, and snippets.

@gabrielizalo
Created July 24, 2017 09:20
Show Gist options
  • Save gabrielizalo/4bf0c720cab93cc05648cf0b4b24a765 to your computer and use it in GitHub Desktop.
Save gabrielizalo/4bf0c720cab93cc05648cf0b4b24a765 to your computer and use it in GitHub Desktop.
Wordpress - JS Dropdown Menu of Tags
// Taken from: https://speckyboy.com/wordpress-snippets-secondary-navigation/
/*
If your site takes advantage of WordPress post tags, it may be useful to provide a simple way for users to navigate between them. This is particularly effective for sites with a lot of tags.
For example, a project I worked on used tags as a way to filter posts by a relevant geographic region (of which there were dozens). This dropdown menu utilizes JavaScript to instantly direct the user to whichever tag they choose. You can also do something similar with categories.
*/
<?php
// Show a Drop Down Menu of Tags
echo "<select onChange=\"document.location.href=this.options[this.selectedIndex].value;\">";
echo "<option>Choose a Tag:</option>\n";
foreach (get_tags() as $tag) {
echo '<option value="' . get_tag_link($tag->term_id) . '">' . $tag->name . '</option>\n';
}
echo "</select>";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment