Adding A Private Page Into The Navigation menu

January 11, 2009 · Print This Article

If you use pages which have the state private, they will not be shown in the navigation. Nevertheless it can make sense to show this specific page in the navigation, if you want to provide easy access to this page for your users. The page should only appear to privileged users for sure. I will show you a little hack, which will let you exactly do this.

simply open the file where your navigation is (You can look up for the wp_list_pages() function) and insert this snippets instead of the function:

<ul>
<?php
wp_list_pages('depth=1&title_li=0&sort_column=menu_order');
if(current_user_can('read_private_pages')) :
?>
<li><a href="<?php echo get_permalink(10); ?>">For Authors only</a></li>
<?php endif; ?>
</ul>

That’s all. Your navigation menu now display private pages to specific users.

The function current_user_can checks, if the current user is privileged to read private pages. If not, then the page will not be shown for him.

Short notice: The 10 at get_permalink(10) is my ID for the page and has to be changed to your scenario.


Your choice for site templates and wordpress themes

Comments

Got something to say?

You must be logged in to post a comment.