Set Posts Per Page For Tag Archive

This code enables you to set the posts per page limit for any tag archive page. This way you can over ride the WordPress > Reading settings which effect all archive page types.

The following code only executes on the tag archive page with a slug tag-one. Replace tag-one with the slug or i.d of your tag.

add_action('pre_get_posts', 'posts_per_tag_archive_page');

function posts_per_tag_archive_page( $query ){
if ( $query->is_tag('tag-one') ) {
    $query->set( 'posts_per_page', 1 );
    return;
    }
}

The following code effects all tag archive pages:

add_action('pre_get_posts', 'posts_per_tag_archive_page');

function posts_per_tag_archive_page( $query ){
if ( $query->is_tag() ) {
    $query->set( 'posts_per_page', 1 );
    }
}

This enables you to display pagination on your tag archives.

The code uses the is_tag conditional tag with pre_get_posts.

Join 5000+ Followers

Get The Latest Free & Premium Tutorials Delivered The Second They’re Published.