> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Customizing the number of search results displayed in WordPress

> Learn how to limit the number of search results displayed on a page in WordPress by adding a brief code snippet to the functions.php file of your theme.

This article describes how to customize the number of search results that [WordPress](https://hosting.com/hosting/platforms/wordpress-hosting) displays per page. You may want to do this, for example, if your site only has a few posts or a large number of posts.

## Customizing search results

To customize the number of search results displayed per page, follow these steps:

1. Log in to WordPress as the administrator.

2. On the Dashboard in the left sidebar, click **Appearance**, and then click **Theme Editor**:\
   ![WordPress - Dashboard - Appearance - Theme Editor](https://static.hosting.com/kb/kb-wordpress-dashboard-appearance-theme-editor.png)

3. In the right sidebar, under **Theme Files**, click **Theme Functions (functions.php)**.

4. Copy the following code snippet and then paste it at the bottom of the *functions.php* file:

```javascript theme={null}
function control_search_results() {
    if ( is _search() )
        set_query_var('posts_per_archive_page', 10); // Change 10 to the number of search results you want to appear per page.
}

add_filter('pre_get_posts', 'control_search_results');
```

5. Click **Update File**. WordPress saves the changes to the *functions.php* file. To test the new code, do a search and confirm that the correct number of results appears per page.

## Related articles

* [Adding a custom logo to WordPress](/docs/adding-a-custom-logo-to-wordpress)

* [Displaying the user count in WordPress](/docs/displaying-the-user-count-in-wordpress)

* [Creating custom shortcodes in WordPress](/docs/creating-custom-shortcodes-in-wordpress)

* [Using widgets in WordPress](/docs/using-widgets-in-wordpress)

* [Installing WordPress themes](/docs/installing-wordpress-themes)
