How to Sort WordPress Category Archive by Post Title?

Here’s a tutorial how you can easily sort your WordPress Category Archive Page by Post Title instead of Published Date. This is helpful in sorting your blogs

how to sort wordpress category archive
How to Sort WordPress Category Archive
  1. Edit the theme function by logging in to your WordPress Admin then go to Appearance -> Theme Editor -> Theme functions.
  2. Make sure you are editing your CHILD THEME FUNCTION as the PARENT THEME will be overwritten when your theme updates.

3. Copy the Code

//function to modify default WordPress query
function wpb_custom_query( $query ) {
// Modify the main query on the Blog / Category Archive
    if( $query->is_main_query() && ! is_admin()  ) {
        // Set parameters to modify the query
        $query->set( 'orderby', 'name' );
        $query->set( 'order', 'asc' );
// Hook our custom query function to the pre_get_posts 
add_action( 'pre_get_posts', 'wpb_custom_query' );

4. Click Update File

Here’s the BEFORE (sorted by publish date)

Here’s the AFTER (sorted by Post Title)