Tag Info

New answers tagged


Use the selected HTML attribute. See w3schools docs. In your foreach loop, check if the current category matches the current iteration, and add the selected attribute to that option element. You are already getting the ID of each term, so you'll need to also get the current category ID so you can check against it. Perhaps I would use get_the_category, to ...


From the looks of this script, as soon as you click an option it redirects you to whatever the category archive is, since that's the case we can just get the current category that the user lands on and compare the current category ID to the category ID in the loop: Here's the modified code: <select name="page-dropdown" ...

Top 50 recent answers are included