how to display wordpress categories in a drop down menu

wordpress tutorial, how to display wordpress categories in a drop down menu. For showing the categories in drop down menu just use our following code.

how to display wordpress categories in a drop down menu

You just need to copy paste following code in put in functions.php file.


<li id="categories"><h2><?php _e('Posts by Category'); ?></h2>
 <?php wp_dropdown_categories('show_option_none=Select category'); ?>

<script type="text/javascript"><!--
 var dropdown = document.getElementById("cat");
 function onCatChange() {
 if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
 location.href = "<?php echo get_option('home');
?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
 }
 }
 dropdown.onchange = onCatChange;
--></script>
</li>

For more information you can use the following code.

how to display wordpress categories in a drop down menu
how to display wordpress categories in a drop down menu

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

One thought on “how to display wordpress categories in a drop down menu”

Leave a Reply

Your email address will not be published.