Move the WordPress pages to the header – revisited

This updated article describes how to use the page widget to build a page menu in the WordPress header. For the background to this see the previous post Move the WordPress page links to the header that described a simple way of listing the page links on the header.

This method makes use of the Pages widget which allows pages to be excluded from the menu and also allows the sort order of the pages to be specified. To view this from the dashboard expand Appearance in the left-hand sidebar then select Widgets. You can then use the Widget to set up a list of page links in the sidebar.

WordPress Pages widget

The first thing is to find the path to the theme that you are using, for the default theme the path is:


For other themes the path will vary so make sure you have identified the correct one for the theme you have in use.

Then using your favourite text editor open up the following files:

  • functions.php
  • header.php

Note: Before you make any changes to these files make sure you have a backup

In functions.php add the following code in an appropriate place.

function list_pages($pages) {
$options = get_option( 'widget_pages' );
foreach ($options as $key=>$value) {
        if ( $pages == $options[$key]['title'])	{
			$sortby = $options[$key]['sortby'];
			$exclude = $options[$key]['exclude'];
        	if ( $sortby == 'menu_order' ) {
				$sortby = 'menu_order, post_title';
			$out = wp_list_pages( apply_filters('widget_pages_args', 
					array('title_li' => '',
					'echo' => 0, 
					'sort_column' => $sortby, 
					'exclude' => $exclude) ) );
        	if ( !empty( $out ) ) {
				<li><?php echo $out; ?></li>

Then add the following line of code in the header.php file. The correct location will vary by theme but generally it will be within the header div.

<ul><?php list_pages('Header1'); ?></ul>

The effect of this will be to list the pages defined by the Pages widget that has a title of Header1, you can edit the the parameter above for list_pages to match the one you are already using. This should work with WordPress 2.8 onwards but probably will not work with previous versions to that.

This entry was posted in Design, WordPress and tagged , . Bookmark the permalink.

We would love to hear from you so please leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.