☀️

How To Change The Order Of Pages In WordPress


Changing the page order in WordPress seems like it should be something intuitive by default, doesn’t it? Adding a page is easy. Editing a page is too. Why is ordering pages so difficult?

Honestly, I’m not sure. In this guide, I’ll show you how to do it manually using the default tools and then also show you an excellent plugin that makes this easy. But first, in case you’re in a rush, here’s a quick answer on how you do it manually.

You can use the “order” field near the update button of the edit page screen (in the page attributes section) to set the “menu order.” The default order number is 0, and that will be the topmost page. For pages, you want to appear after it, increment the number. So the order would be 0, 1, 2, 3, and so on.

Remember, we’re talking about pages, not posts. Posts are sorted in reverse chronological order by default. Pages are different.

Let’s get into this.

Why Change the Page Order?

Technically, changing the page order in your admin has little effect on the front-end view your readers see. That’s because things like archive pages, category pages, etc… show posts, not pages. 

Pages are generally viewed individually and not in a list. So why would you want to change the order?

Well, it could be a simple as you want to because you like order and want the most important pages to appear at the top so you can edit them more easily. 

But there are more advanced use cases such as created nested pages for a custom learning management system (which I will show how to do in the future). 

The reason is your own personal reason and I want to show you have to achieve your goal. To do that you’ll need to understand the default page order first.

Default Page Order

By default, pages are in alphabetical order by page title. Just go to your admin dashboard > all pages to confirm this. Or if you are using widgets to display a list of pages (like a submenu), you’ll see the pages are in alphabetical order

But you may be surprised to learn that technically, pages are in “menu_order” order. But since every page defaults to 0 (zero) in the order field, they are sorted alphabetically based on the page title.

But this means you can change it! To change this the manual way you’ll need to find the order field on each page and change it.

The Order Field

To understand the page order you must understand there is an “order” field for every page. This field is a number representing the order of the page (as the name suggests). Technically, behind the scenes, the “order” field is called the  “menu_order.” Developers could use that field in database queries for a custom order.

Note: while you can use negative numbers in this field, there have been times in WordPress’ development where this stops working. I recommend only using positive numbers.

Reordering the Page Order Manually

Since each page you create defaults to zero, this is where things become very manual. If you have a lot of pages to order it will be downright annoying.

But you have to go to the edit page of every page and manually set the order number. And remember, the higher the number, the “later” it loads. Zero is first, and pages with higher numbers in the order field come after it (and after each other subsequently as the number gets higher).

As you can imagine, doing this manually is quite a task. Because you have to set every page’s order number and keep doing this when you create new pages. And what if you want to shuffle things around a little? You have to go back through and edit each one to get them out of the way.

There is definitely a better way — and of course, the answer is with plugins! (note, the Simple Page Ordering plugin, and Post Types Order plugin work great, but I prefer something else.)

Nested Pages Plugin

This is a plugin I add to every WordPress website I create. In fact, this is how I think the “all pages” view in the dashboard should look.

This plugin brings more useful functionality than just reordering pages, but since this guide is specifically about page order — I won’t get into depth on the Nested Pages plugin (maybe in the future).

Drag and Drop

Of course, you can still use the order field to manually order pages, but Nested Pages gives you the ability to drag and drop them. So much easier.

Just move them around to the order you want and that’s it. All done.

Heads up: I have had problems dragging and dropping with this plugin before, be sure to clear your browser cache after installing it to clear out cached scripts that might interfere.

All Pages at Once

In the default “all pages” view the list of pages is paged. You can go to the screen options at the top to change how many pages are shown at once.

But the Nested Pages plugin shows all the pages in one view so you don’t have to worry about it.

Pages in Navigation

Normally I would say this is almost a different topic, but it is related so I want to add a bit of context here because you may have a menu consisting purely of pages — and you want to change the menu order.

To do that you simply go to “Appearance > Menus” and then you can drag and drop the menu item (pages) to the custom order you want. 

You can do this in any custom menu you create (and assign in your theme). And a bonus tip, don’t forget you can change the link text of any menu item from the same screen you reorder the menu items.

Listing Pages Using Code

What if you wanted to a page of your site where readers could see pages? Listed in the custom order you want of course.

After you have already set the page order (preferably by using the Nested Pages plugin for ease) and if you have the dev chops to dig into your theme and edit WP_Query, you could easily add a query something like:

$args = array(
    'orderby' => 'menu_order title',
    'order'   => 'DESC',
);
$query = new WP_Query( $args );

Then loop through the query and “do stuff” when each page found, like so:

if ( $query->have_posts() ) {
    echo '<ul>';
    while ( $query->have_posts() ) {
        $query->the_post();
        echo '<li>' . get_the_title() . '</li>';
    }
    echo '</ul>';
} else {
    // no pages found
}

wp_reset_postdata();

These code samples are from the official WordPress WP_Query documentation.

If you look closely you’ll see it says the_post() but that is the page… something you’d have to know as a WordPress developer. Technically, everything is a post, but WordPress allows for custom post types and “page” is a default custom post type.

I won’t dive more deeply into this… as it is more of a developer topic. But once you have appropriately added it to your theme template (and applied it to the page you want readers to see), you’ll have a cool, custom page with other pages listed within — in the order you want.

Nice work!

Additional Resources

Here are some other places where you can learn more about page ordering in WordPress.

  • “Not all themes display Page hierarchies by default in the navigation menu. If this is the case with the theme you are using, then you can use the Custom Menus feature to create sub-pages and to customize your navigation menus.” (wordpress.com)
  • “When WordPress aligns these pages across navigational areas, it uses a hierarchical alignment. This means that users can set which page comes first in a particular order. Otherwise, the system will arrange them either by date published or alphabetical order whichever your default installation uses. What if you want to arrange them in a specific way?” (greengeeks.com)
  • “Back when WordPress did not have the awesome menus, developers utilized this page ordering function to order their menus. However, it was a big pain. Let’s say you ordered your pages 1-10 respectively. Now if you wanted to change the order, you have to modify other page orders as well. Simple Page Ordering plugin makes that job very easy.” (wpbeginner.com)
  • “Simply drag and drop the page into the desired position. It’s that simple. No new admin menus pages, no clunky, bolted on user interfaces. Just drag and drop on the page or post-type screen.” (wordpress.org)

Summary

In this guide, I discussed the odd default page order and how you can override it manually — and also how to use the awesome Nested Pages plugin to make this task easier.

And also how you might dig into the code to hack your own page list that abides by the order you desire.

I hope you found it helpful and I’ll see you in the next guide.

Take care,

🐹, ✌️+❤️