Most small business sites I move off WordPress have a search box nobody thinks about. Then the new Astro site goes live, the client types "opening hours" into the header search and gets a 404. Ask me how I know.
WordPress search works because there's a database and PHP behind every request. A static Astro site has neither, so search is one of those things you have to replace on purpose. My default now is Pagefind. It indexes the built HTML after the build and ships a small search bundle as plain static files. No server, no API key, no monthly search bill.
Here's the exact process I run on every migration.
1. Check if they actually need search
Before I add anything I look at the old site. Two quick checks:
- Is there a search box in the theme header or sidebar?
- Do the server logs or analytics show any
?s=URLs?
If a 12 page tradie site has zero ?s= hits in a year, I drop search completely and tell the client why. Less stuff to maintain. If it's a blog with 200+ posts, a big menu, a product list or docs then search definately stays.
2. Add Pagefind as a post build step
Pagefind runs on the output folder, not your source. In package.json:
{ "scripts": { "build": "astro build && npx pagefind --site dist" } } That writes a /pagefind/ folder into dist with the index and the UI files. Because it's just files it deploys like everything else.
3. Tell it what to index (and what not to)
Out of the box Pagefind indexes the whole page, which means your nav, footer and cookie notice end up in every result. I add one attribute to the main content wrapper in the layout:
<main data-pagefind-body> <slot /> </main> Once any page has data-pagefind-body, only those regions get indexed. Then I tag the bits that are noise:
<aside data-pagefind-ignore>Related posts...</aside> And for pages that should never show up in search (thank you pages, legal stuff, the 404), I just leave data-pagefind-body off that layout. Done.
4. Drop in the UI
I put this on a /search page so the header search box can just be a normal form:
--- // src/pages/search.astro import Layout from "../layouts/Layout.astro"; --- <Layout title="Search"> <link href="/pagefind/pagefind-ui.css" rel="stylesheet" /> <div id="search"></div> <script is:inline src="/pagefind/pagefind-ui.js"></script> <script is:inline> window.addEventListener("DOMContentLoaded", () => { const ui = new PagefindUI({ element: "#search", showSubResults: true }); const q = new URLSearchParams(location.search).get("q"); if (q) ui.triggerSearch(q); }); </script> </Layout> The header form is boring HTML:
<form action="/search" method="get"> <input type="search" name="q" placeholder="Search" /> </form> No JS on every page, the search bundle only loads on /search.
5. Keep the old WordPress search URLs working
This is the bit people miss. WordPress search URLs look like /?s=opening+hours and they're sitting in bookmarks, old emails and sometimes Google. Some hosts let you match query params in _redirects, some dont, so I stopped relying on it. Instead the homepage gets a tiny inline script:
<script is:inline> const s = new URLSearchParams(location.search).get("s"); if (s) location.replace("/search?q=" + encodeURIComponent(s)); </script> Old link comes in, lands on the new search page with the term already filled in. Works on any static host.
6. Make my coding agent test it before launch
I don't trust myself to remember this so it's in the seperate launch checklist my agent runs (Claude Code or Cursor, whichever is open). The checks:
-
dist/pagefind/exists after build - searching 3 terms I pull from real page titles returns those pages
- searching something from the footer returns nothing (proves the ignore rules work)
-
/?s=testends up on/search?q=test
If any of those fail, no deploy. When they pass it's npx novence deploy and the index goes live with the rest of the site on novence.ai. Since the index is rebuilt every build, new posts are searchable the moment they publish. No reindex job, no plugin.
7. Watch what people search for
Pagefind doesn't track anything, which I like. But the search terms are gold for the client: they tell you what's missing from the nav. Because the term ends up in the /search?q= URL, it shows up in page views in plain cookieless analytics. Once a month I glance at the top terms. "Prices" showing up 40 times usually means the pricing page needs to be in the menu, not hidden in the footer.
What it replaced
On a typical migration this gets rid of the theme's AJAX search, a "better search" plugin and whatever relevance tweaks someone added to functions.php years ago. The new search is faster, more accurate (it only reads the actual content) and costs nothing to run.
Total time per site is about 30 minutes now that it's a checklist. If you're moving client sites to Astro, do the search box on purpose before the client finds out the hard way.

