# Sort the Pages List Alphabetically by Default

> Opens Pages sorted by title from A to Z instead of the default order, which makes finding a page on large sites much faster. Clicking a column header still sorts as usual.

- Type: PHP
- Runs: Admin only
- Category: [Admin](https://wpide.com/library/category/admin/)
- Tags: pages, sorting, admin-lists
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/admin-pages-alphabetical-default/

## Code

```php
// Post types listed A to Z by default.
$wpide_alpha_post_types = array( 'page' );

add_action( 'pre_get_posts', function ( $query ) use ( $wpide_alpha_post_types ) {
    global $pagenow;

    if ( ! is_admin() || 'edit.php' !== $pagenow || ! $query->is_main_query() || isset( $_GET['orderby'] ) ) {
        return;
    }
    if ( in_array( $query->get( 'post_type' ), $wpide_alpha_post_types, true ) ) {
        $query->set( 'orderby', 'title' );
        $query->set( 'order', 'ASC' );
    }
} );
```

## Notes

Change $wpide_alpha_post_types to sort other post types alphabetically as well.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Sort the Pages List Alphabetically by Default" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
