Skip to content
StaticScope
Overview
Get StaticScope

Search with Pagefind

Build a Pagefind index into the static site, choose a search page and control what gets indexed.

Features Updated 20 November 2026 6 min read

Static hosts cannot run WordPress search. A search box either does nothing or sends every visitor to the home page. The Pagefind add-on fixes that by building a search index into the generated site, where the visitor’s browser searches it.

There is no search server and no query to WordPress. The index is a set of files under /pagefind/ in the build, so it travels with the site into the preview, the ZIP and every deployment.

What Pagefind is

Pagefind is a separate program that reads a folder of HTML, writes an index and supplies a small browser library to search it. It splits the index into chunks, so a visitor downloads only what a query needs. The add-on bundles version 1.6.0 and runs it for you.

What it needs

PHP must be allowed to run another program. The add-on checks for proc_open and reports the problem if it is missing or disabled. The bundled binaries cover Linux on x86-64 and ARM64, macOS on Apple silicon and Intel, plus Windows on x64. Windows on ARM runs the x64 binary under emulation.

On another system or version, install Pagefind and set the path under StaticScope → Search, or define STATICSCOPE_PAGEFIND_PROGRAM in wp-config.php. The path field is only shown to users who can install plugins, and only when the constant is not set.

Indexing has a 900-second limit and the version check has 15 seconds. The add-on’s ZIP is about 23 MB because it carries all five binaries; a host that rejects the upload needs the folder copied into wp-content/plugins or installed with WP-CLI.

Set up the search page

Search results appear on an ordinary WordPress page containing the Static search results block. The screen can create a page called Search for you, or you can choose a published page that already has the block. A draft page is not enough: the add-on treats it as having no search page, so no redirects happen.

SettingWhat it does
Show results onA published page. Results and rewritten search forms point here
Include archives and listsOff by default. On indexes category, tag, date and other listing pages too
Pagefind programOptional full path to another Pagefind binary

Archives are off by default on purpose. Indexing both a post and the lists that repeat its title makes every result look like a duplicate. Turning the setting on is all-or-nothing; there is no per-archive choice.

Indexing at build time

The index is built when StaticScope finishes preparing the site. The command is equivalent to pagefind --site <prepared site> --exclude-selectors <list>. By default it leaves out comments and the reply form, post navigation and query loops, because those repeat content and make everything match everything.

After indexing, the add-on removes the Pagefind files used by older interfaces, records the page count, duration and version, and deletes the StaticScope preview so it cannot show a stale index. A failed index is logged and recorded but does not fail the build; the site check then reports the missing search files.

How search behaves

  • Search forms on the static site are retargeted to your search page. This only applies to GET forms with role="search" or an input named s that submit to this site’s own root. Another site’s form is untouched.
  • Old links such as /?s=term are sent to the search page by a small script in the home page.
  • The results page reads the s parameter, searches and keeps the address in step with history.replaceState.
  • Without JavaScript the page says search needs JavaScript. On WordPress itself, before a build, the block shows “Search works on the static site” instead.

Style the results with Pagefind’s --pf-* custom properties. The block class is wp-block-staticscope-pagefind-search-results, so a theme can scope them there.

Control what is indexed

By default the add-on marks single posts, pages and custom post types for indexing. It looks at the body classes WordPress adds, then puts data-pagefind-body on the page’s <main> element, or on <body> when there is no main element. The search page is skipped.

If a page already contains data-pagefind-body, the add-on leaves it alone. That lets a theme take over: put the attribute on the template part that holds the content, and Pagefind indexes only marked pages. Use data-pagefind-ignore on a sidebar, share bar or related-posts block that should not be searched.

To exclude repeated parts across the whole site, filter staticscope_pagefind_exclude_selectors and return your own CSS selector list. The defaults cover comments, navigation and query loops.

Multilingual sites

The add-on has no language setting. Pagefind reads each page’s lang attribute and keeps a separate index per language, and it searches the language of the page the search box is on. That only works if your theme outputs the language on <html>, which language_attributes() does.

Because the add-on selects one search page, a multilingual site gets results for that page’s language unless you build each language separately or give each language its own site and search page. Pagefind’s interface strings are its own, in English by default; the add-on does not translate them.

Rebuild after changing settings

The index itself is built fresh on every generation, but the search page choice, archive setting and form rewrites are applied while the site is generated. Change any of them and build again. wp staticscope pagefind index is a repair tool for the existing export; it does not reapply those settings.

Who can change it

The Search screen is restricted to manage_options. The program path has a second check: only users with install_plugins can change it, and a user without that capability keeps the existing value even if the form is submitted.

WP-CLI

wp staticscope pagefind status
wp staticscope pagefind index

status prints the program status, the chosen search page and the last index result. It exits 1 when Pagefind is not ready, which makes it usable as a pre-flight check. index rebuilds the index for the existing prepared site and errors when there is no site or indexing fails.

Failures to expect

  • No proc_open. Common on shared hosting. Run npx pagefind --site path/to/exported-site in your deployment instead.
  • The binary cannot run. WordPress unzips plugins without execute bits. The add-on sets 0755 when it can; if chmod fails, the status says so.
  • macOS is waiting for permission. A Finder-unzipped plugin carries the quarantine mark. The add-on removes it only when the checksum matches, so a replaced binary can hang until the timeout.
  • No results. Check the search page is published, has the block and is the chosen page, then check the /pagefind/ files are in the build.
  • Everything matches. Archive indexing is on, or data-pagefind-body is missing from a theme that opted out.

Hooks

staticscope_pagefind_exclude_selectors changes the selector list passed to Pagefind. The add-on also uses StaticScope’s staticscope_discovered_paths, staticscope_runtime_paths and staticscope_process_html to keep the bundle out of the crawl and mark pages.

Next