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.
Why Customize Search Results?
-
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.
Steps to Customize Search Results
-
Log in to WordPress with an administrator account.
-
In the dashboard, go to Appearance → Theme Editor.
-
Select your active theme and open the functions.php file.
-
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
10with the number of search results you want to display per page.
-
-
Save the file.
-
Test by performing a search → The new number of results will appear per page.
Important Notes
-
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.