Modify Posts Per Page for Archives

This snippet changes the number of posts displayed per page on archive pages, allowing for custom pagination.

PHP

function modify_archive_posts_per_page($query) {
    if ($query->is_archive() && $query->is_main_query()) {
        $query->set('posts_per_page', 15);
    }
}
add_action('pre_get_posts', 'modify_archive_posts_per_page');

Snippet Feedback

Did this snippet work for you? Do you have any questions about this snippet? Leave some feedback below.

Tags

Language

Did it work?

Save Snippet

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.

Embed Snippet

To embed this snippet on your site, copy this html code and paste into your webpage. Learn more
By embedding snippets on your site, you are agreeing to our terms and conditions.