Skip to main content
100%

Custom post_per_page

✓ Published0🌍 Public
KKopylovVitalik
Last edited Jul 30, 2020
Created on Jul 30, 2020

This example shows how to customize the number of posts displayed on different WordPress pages using the `pre_get_posts` action hook. It sets `posts_per_page` to 8 for the home page, 4 for search results, and 15 for the “novosti” page, while commented-out code hints at potential archive and category-specific adjustments. The code defines a `custom_posts_per_page` function that checks WordPress conditional tags like `is_home()`, `is_search()`, and `is_page()`, then modifies the main query object accordingly. It relies entirely on WordPress core APIs, including `$query->set()` and `add_action()`, with no external libraries or rendering involved.

AI-generated description

Similar vizzes