Use the parse_query
hook to override the default main query:
add_action( 'parse_query', function ( WP_Query $wp_query ) {
/**
* Only apply our custom ordering when:
* - We're not in the admin
* - It's an archive (i.e. not singular)
* - It's the main query (won't affect custom WP_Query)
*/
if ( ! is_admin() && ! $wp_query->is_singular() && $wp_query->is_main_query() ) {
$wp_query->set( 'orderby', 'title' );
$wp_query->set( 'order', 'DESC' );
}
});
This needs to live in a plugin or your theme’s functions.php
.