Article updated in November 2026.
By default, the "Pages" list in the WordPress admin is shown in hierarchical order: by menu order, then by title. That is handy for site structure, but not when you want to see the newest pages first. There are two ways to change it: with a small code snippet or with a plugin. The most reliable one is a short snippet that changes the default order of the pages list in the admin panel.
Option 1: code in functions.php (recommended)
This snippet sets sorting by creation date (post_date) in descending order (newest first) for the page post type in the admin. It applies only when you have not chosen a sort order yourself:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
function avalyst_sort_pages_by_date_default( $query ) { if ( ! is_admin() || ! $query->is_main_query() ) { return; } global $pagenow; if ( 'edit.php' !== $pagenow || 'page' !== $query->get( 'post_type' ) ) { return; } if ( ! isset( $_GET['orderby'] ) ) { $query->set( 'orderby', 'date' ); } if ( ! isset( $_GET['order'] ) ) { $query->set( 'order', 'DESC' ); } } add_action( 'pre_get_posts', 'avalyst_sort_pages_by_date_default' ); |
This version checks $pagenow and the query’s post type instead of calling get_current_screen(). The screen object is not always available when pre_get_posts runs, so the check is safer.
How it behaves
- Open "Pages" → "All Pages". The list is sorted by date, newest first, instead of the default hierarchical order.
- If you click a column header (Title, Date and so on), the choice is passed in the URL as
orderbyandorder. The snippet does not override it. - WordPress does not remember that manual choice between visits. Next time you open the list, the date order from the snippet applies again.
- Only the admin list is affected. The front end of the site is not changed.
Where to put the code
Add it to the functions.php of a child theme, or to a small custom plugin or a code-snippets plugin. Code added to the main theme’s functions.php is lost when the theme is updated. Make a backup before editing theme files. A syntax error can break the site.
Option 2: plugin
Plugins such as Admin Columns or Simple Page Ordering help customise the pages list or let you reorder pages manually. They are not designed to force a stable default sort by date, and the result depends on the plugin settings. For that reason the code from option 1 is the better choice.
How an AI assistant can help
An assistant such as Claude can adapt this snippet to another post type or to sorting by modified date or title, and can review it for syntax errors before you paste it into a live site. Always test the result on a staging copy first.
Leave a Reply