Articles on: WordPress

Advanced Level: How to Add Navigation to Your Sidebar in WordPress

Besides using widgets, there are several ways to add Pages, Archives and even Categories into your WordPress blog.

Below we try do modify such pages by adding relevant codes into our Themes sidebar.php file.


Login to your WordPress dashboard and click on Appearance >> Editor.




Locate sidebar.php file on the right navigation bar under Theme Files.



Once the file opens you will see the php code that governs the sidebar display and behavior.

From here you will be able to add the code to populate the sidebar with navigation links for Pages, Categories, or Archives.

Below are the code samples you would need to add to your sidebar.php file

Pages
<?php wp_list_pages('title_li=<h2>Pages</h2>'); ?>





Categories
<?php _e('Categories:'); ?> <ul> <?php wp_list_cats(); ?> </ul>




Archives
<?php _e('Archives:'); ?> <ul> <?php wp_get_archives('type=monthly'); ?> </ul>





Remember to click on Update File button in order to save every changes you've made.

Final note:
Once you have performed the above steps, you can visit your site to see the additional navigation links you have added. You are able to adjust the formatting (font, etc) by adding inline custom CSS or adjusting your style.css file.

Updated on: 17/01/2019

Was this article helpful?

Share your feedback

Cancel

Thank you!