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

  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.

 

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.

 
Cette réponse était-elle pertinente ? 0 Utilisateurs l'ont trouvée utile (0 Votes)

Powered by WHMCompleteSolution