21+ years in hosting · Jaipur, India · INR billing with 18% GST · 24/7 email support
Blog · WebJi® India

Customize WordPress Search Results

Quick answer

In a block theme, edit the Search Results template under Appearance, Editor, Templates and change its Query Loop block; in a classic theme, copy search.php into a child theme. Narrow post types with a pre_get_posts filter, and expect date order, not relevance, in core WordPress.

For WordPress site owners in India who want the search page to match their theme and return the right results.

✓ In business since 2005
✓ INR + GST billing
✓ 24/7 Email Support — avg reply < 60 min
GuideWebJi®
knowledge
Read time
4 min
Sections
7
Updated
14 Nov 2026
Written by
WebJi® team

Where is the WordPress search results page edited?

Block themes keep the search page in Appearance → Editor → Templates → Search Results; classic themes keep it in the theme's search.php file. The template decides what one result looks like — title, excerpt, image, spacing — and both routes are safe to change as long as you never edit a parent theme directly.

  1. In the WordPress admin, open Appearance → Editor (older versions label it Site Editor).
  2. Click Templates, then open Search Results.
  3. Open List view to see the structure: the heading block sits above the Query Loop block that prints the results.
  4. Select the Query Loop block, use Replace on the block toolbar to pick a different pattern, then add a Post Excerpt block and set the featured image aspect ratio so thumbnails match.
  5. Click Save and run a search on the front end to confirm the new layout is live.

On a classic theme there is no Search Results template in the editor. Copy search.php from the parent theme into a child theme and edit the copy, because a theme update overwrites the parent file. The same rule covers any CSS you add for the results page.

How do you change which post types the search returns?

Hook a small function to pre_get_posts and set the post types, results per page and order for the main search query only. WordPress core searches posts and pages by default; the filter is how you add products, portfolio items or custom post types — or remove pages altogether.

add_action( 'pre_get_posts', 'webji_search_types' );
function webji_search_types( $query ) {
    if ( $query->is_search() && ! is_admin() && $query->is_main_query() ) {
        $query->set( 'post_type', array( 'post', 'page', 'product' ) );
        $query->set( 'posts_per_page', 12 );
    }
}

Put the snippet in the child theme's functions.php or in a snippets plugin if you would rather not touch theme files. The three guards matter: pre_get_posts fires for every query WordPress runs, so without is_main_query() the filter also rewrites the queries behind menus, widgets and related-post blocks. Drop product from the array on a site without a shop, and only add a custom post type when its single template can render the result properly. In block themes the filter still works, because the Query Loop in the Search Results template runs as the main query.

Can WordPress rank search results by relevance?

Core WordPress does not rank search results by relevance — it orders them by date and matches only the title, excerpt and content. A term that appears only in an image caption, a custom field or a PDF filename will not be found at all, and a post from 2019 that mentions the term once outranks a fresh post built around it.

  • What core search does: splits the phrase into words, requires each word somewhere in the title, excerpt or content, then sorts by publish date.
  • What it cannot do: no OR, quoted-phrase or minus-operator searches; no weighting; no indexing of custom fields, taxonomies or media.
  • Plugin route: Relevanssi and SearchWP index custom fields and attachments, support partial-word matches and let you weight the title above the body. Licence terms and pricing sit with each vendor — check them before committing a client site.

Treat relevance as a plugin feature, not a template edit. If exact-phrase behaviour is a requirement, test the plugin on staging and rebuild its index before judging the results.

How do you style search results so a theme update cannot wipe them?

Block themes are styled in the Site Editor under Styles; classic themes need CSS inside a child theme, never inside the parent. Both routes survive the next theme update, which is the only rule that matters for a site you maintain beyond launch week.

Keep each result lean: linked title, short excerpt, one image. A results page that prints full posts is slow on Indian mobile connections and hard to scan, and readers rarely scroll past the first matches. Compressing the thumbnails first helps too — the image compression guide covers that without visible quality loss.

What should you test before launching the search page?

Run the same four searches after every template change so runs are comparable: a body-only phrase, a nonsense word, page two, and one search on a phone. These four checks catch the failures editors notice after launch, not before.

  1. Search a phrase that appears only in body text, not in any title — it must still return its post.
  2. Search a random string such as zzqxv — the no-results message and the search form should both render.
  3. Open page two of a broad search and confirm pagination still works after your posts_per_page change.
  4. Repeat one search on a phone, because stacked patterns and wide excerpts overflow narrow screens first.

Why does the saved template not appear on the live site?

Most of the time the template saved fine and a page cache or CDN is still serving the old HTML, so purge caching before touching code again. Clear the page cache (LiteSpeed Cache purge, your caching plugin or the CDN), clear the object cache, then reload in a private window. Only if the old layout persists is the cause one of these:

Search template symptoms and fixes
SymptomCause and fix
New layout in the editor, old layout on the sitePage cache or CDN. Purge, then reload in a private window.
Template edits do nothing at allClassic theme — edit search.php in a child theme instead.
Child-theme changes vanishThe file was edited in the parent theme. Move it to the child.
Search returns everything, even menusThe pre_get_posts filter is missing the is_main_query() check.
Layout broken after a pattern swapOpen the template's three-dot menu and choose Clear Customizations, then rebuild.

The template lives inside limits the host sets — caching layers, PHP workers, backups. WebJi®'s WordPress hosting plans and the speed optimisation service are the two places those knobs get tuned for WordPress sites hosted here.

Where does the host come in?

The template and the query filter are yours; the host decides the caching layer, PHP limits and backups around them. WebJi®'s WordPress plans — read from WebJi® billing on 15 November 2026 — run WordPress Unlimited at ₹400 a month and WordPress Unlimited+ at ₹500 a month before 18% GST, with unlimited storage and bandwidth, a WP install wizard, staging tools and daily backup; staging is the right place to test a pattern swap before it goes live. If a template edit still will not appear after a cache purge, email support@webji.services with the URL and the test term; support answers round the clock in Hindi and English.

FAQ

Frequently asked questions

How do I customize the WordPress search results page?

In a block theme, open Appearance, Editor, Templates and Search Results, then change the Query Loop pattern and save. In a classic theme, copy search.php into a child theme and edit the copy so theme updates cannot overwrite it.

How do I exclude pages from WordPress search?

Hook a function to pre_get_posts that sets post_type to post only, guarded by is_search(), is_admin() and is_main_query(). Search plugins such as Relevanssi can restrict post types from their settings screen instead of code.

Why is my search template change not showing?

Usually a page cache or CDN is still serving the old HTML. Purge the cache, clear the object cache and reload in a private window. If nothing changes, the site runs a classic theme and the edit belongs in the child theme's search.php.

Can WordPress search custom fields?

Not in core. Relevanssi and SearchWP index custom fields; add the field keys in the plugin settings and rebuild the index, then retest with a phrase that exists only in that field.

Should search results pages be noindexed?

Usually yes. Search URLs are thin and often duplicated, so most SEO plugins noindex them with one setting while leaving the posts they link to indexed. Internal site search is for visitors, not for Google.

Last editorial update: 15 November 2026. Prices follow the dated sources on this page; checkout confirms current charges.

WebJi® since 2005

Ready to get started with WebJi®?

Join 12,000+ businesses across India and overseas. INR pricing, 18% GST shown before payment and 24/7 email support in Hindi and English — average first reply under 60 minutes.