Skip to content

Customizing the number of search results displayed in WordPress

By default, WordPress shows 10 search results per page. Depending on your site’s content, you may want to increase or decrease this number. On ruachost.com, you can customize search results using a simple PHP function.

  • Improve user experience by limiting or expanding results.
  • Reduce clutter if your site has many posts.
  • Display more results for content‑heavy sites.
  • Control pagination and layout consistency.
  1. Log in to WordPress with an administrator account.

  2. In the dashboard, go to Appearance → Theme Editor.

  3. Select your active theme and open the functions.php file.

  4. Add the following code snippet:

    // Control the number of search results per page
    function ruachost_control_search_results($query) {
    if ($query->is_search() && $query->is_main_query()) {
    $query->set('posts_per_page', 10); // Change 10 to your desired number
    }
    }
    add_action('pre_get_posts', 'ruachost_control_search_results');
    • Replace 10 with the number of search results you want to display per page.
  5. Save the file.

  6. Test by performing a search → The new number of results will appear per page.

  • Always back up your theme before editing functions.php.
  • Use a child theme to preserve changes during updates.
  • Test thoroughly to ensure pagination works correctly.