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.
Opens WPIDE on
Code
// 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 add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.