DEV Community

Antonio
Antonio

Posted on

I almost edited 25 documentation pages by hand. Then one WordPress plugin did it in 1 second.

aiuto

I'm building BeeEngine JS, a lightweight 2D game engine for the browser, and I'm writing its documentation on WordPress, one page per module.

Every doc page has the same sidebar listing all the modules. While a guide isn't written yet, its link is just an anchor:

<li><a href="#BeeAnimatedSprite">BeeAnimatedSprite.js</a></li>
Enter fullscreen mode Exit fullscreen mode

When I publish the real guide, that link has to point to the new page... on every single page.

The painful way

Open page → Edit → find the line → paste the URL → Save. Repeat 25 times. Then again for the next module. And I still have ~50 pages of docs to write. 😩

The 1-second way: Better Search Replace

Better Search Replace searches and replaces text directly in the database. Yes, many WordPress devs already know it (it's a classic for site migrations), but if you write docs in WordPress and you've never used it, this is for you.

Search for:

href="#BeeAnimatedSprite"
Enter fullscreen mode Exit fullscreen mode

Replace with:

href="https://beeenginejs.com/animazione-spritesheet-in-javascript-play-update-e-draw/"
Enter fullscreen mode Exit fullscreen mode

Table: wp_posts (your prefix may differ, mine wasn't wp_).

The dry run said 444 cells. I panicked for a second, then realized: 25 pages + all their revisions. Totally normal.

I ran it. 1,144 ms. Done. Every page updated. I almost cried. 😂

My checklist so you don't break anything

  1. Back up the database first. The change is permanent.
  2. Always do the dry run and check the count makes sense.
  3. Search something unique, like the full href="#Module", not just Module.
  4. Clear your cache (LiteSpeed, etc.) or you'll still see the old links.
  5. Open a page and click the link to verify.

The trick I'm keeping for the next 50 pages

I write every not-yet-published link as href="#ModuleName". When the guide goes live, one search & replace and the whole documentation is linked. No more opening pages one by one.


If you know an even better workflow for multi-page docs in WordPress, tell me in the comments. And if you like tiny 2D JS engines, come say hi at beeenginejs.com 🐝

Top comments (0)