How to Exclude Posts and Pages from the Menu in WordPress

Sometimes there is a condition arises when we don’t want to display all pages & posts in widgets and menus. In the sidebar, when we display recent posts or pages, it will list there according to date & time. But sometimes, we want to show some desired pages or posts in the sidebar. We can exclude them with different categories but what to do when we have to show only selected pages or posts attached to same category?. So here is a simple trick by which, we can exclude pages & posts from the menu.

A menu can be located in any of the theme files. Mostly, it is located in sidebar.php. Open that file and locate the following code:

<?php wp_list_pages();?>

 
Replace the above code with the following code:
 

<?php wp_list_pages('exclude=12,14' ); ?>

 
Here, 12 and 14 are the page ID. You have to check the page ID of the pages which you don’t want to show on the menu. The page ID’s which you entered here will not visible on the menu. You can get more details on WordPress codex.

The same thing we can do with the use of a plugin named Exclude Pages. But if you have some knowledge of PHP, then you should go with the above example because the use of the extra plugins may affect the performance of your website.

We hope you like this article. If you have any query, you can ask in below comment box.

You can also check How to Add a Mega Menu on Your WordPress Site.

Spread the love

Kapil Garg

Kapil Garg has 7 years of experience in building professional websites. He is a leading web developer, web designer and Google adwords certified partner. His passion is to designed and developed most impressive websites.

Leave a Reply

Your email address will not be published. Required fields are marked *