Capture WordPress Pages on Publish

You can keep a WordPress site on record without touching WordPress, with a webhook plugin, or with a small file in wp-content/mu-plugins. The first two find an updated page through its <lastmod> in the sitemap, which WordPress writes for posts and pages since version 6.5. The file names the page in its call, so it works without that date.

New posts and pages Edited posts and pages What you change
Daily check Within a day Within a day, if the sitemap has a <lastmod> for the page Nothing in WordPress
Webhook plugin A few minutes after publishing A few minutes after the update, if the sitemap has a <lastmod> for the page A plugin and its settings
Must-use plugin About two minutes after publishing About two minutes after each update One PHP file and one line in wp-config.php

Prerequisites


Without touching WordPress: the daily check

WordPress publishes a sitemap index at /wp-sitemap.xml (since version 5.5). It lists the posts, pages and custom post types that are public, and the category, tag and author archives, with up to 2,000 URLs in each sitemap file. An SEO plugin may replace it with its own: Yoast SEO serves /sitemap_index.xml.

Give WRL the sitemap's address and turn on the daily check:

curl -X PUT https://api.webresourceledger.com/v1/sites/example.com \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"sitemapUrl": "https://example.com/wp-sitemap.xml", "dailyCheck": true}'

Once a day WRL reads the sitemap and captures the pages your account has no capture of, then the pages whose <lastmod> is later than their latest capture, up to 100 per check. The first check runs within a few minutes of this call, so the first 100 pages you already have are recorded without another call. For more than 100 pages, send POST /v1/sites/example.com/check with the body {"maxCaptures": 300}, with your number of pages in place of 300 (1,000 at most), or let the daily check record the next 100 each day.

Add a site under Sites in the dashboard sets this up too and captures the pages you already have. It asks for the sitemap's address if it can't read one at /sitemap.xml.

What WRL needs from the sitemap:

  • It is public. WordPress turns its sitemap off while "Discourage search engines from indexing this site" is ticked under Settings, Reading.
  • Its URLs are on the host you gave WRL. www.example.com and example.com are two sites.
  • Each file is plain XML of at most 5 MB. WRL doesn't read .xml.gz files.
  • A check reads up to 5,000 URLs from up to 50 sitemap files. For a larger site, send the pages through the hook.

The daily check records each new post within a day, and an edited one when your sitemap gives it a last-modified date: open the sitemap and look for <lastmod> next to each address. It doesn't capture the home page or an archive again when a new post changes them, unless the sitemap's date for them changes too. For the pages where that matters, add a schedule.


With a webhook plugin

A webhook plugin calls a URL when something happens in WordPress. Point one at your hook URL and each new post is on record a few minutes after you publish it.

On WordPress.com sites that run without plugins, webhooks are built in: add /wp-admin/options-general.php?page=webhooks to your site's address, choose the action publish_post (and a second webhook for publish_page) and enter the hook URL. WordPress.com runs both actions when a post or page is published and when a published one is edited.

On a self-hosted site, a plugin such as WP Webhooks sends data "on new post, update post and delete post" to a URL you enter.

Both send a description of the post as the body. WRL finds no list of URLs in it and runs a check, which captures the new post from the sitemap. The check captures an updated post when the sitemap gives it a <lastmod> later than its latest capture, which WordPress does since version 6.5. Without that date the check leaves it alone. If your plugin lets you write the body yourself, send {"urls": ["https://example.com/the-post/"]} with the post's address, and updates are captured whatever the sitemap says.


With a must-use plugin

This file asks WRL to capture a post or page each time it is published or updated. Save it as wp-content/mu-plugins/wrl-capture-on-publish.php:

<?php
/**
 * Plugin Name: WRL capture on publish
 * Description: Asks Web Resource Ledger to capture a post or page when it is published or updated.
 */

add_action( 'transition_post_status', 'wrl_capture_on_publish', 10, 3 );

function wrl_capture_on_publish( $new_status, $old_status, $post ) {
	if ( 'publish' !== $new_status || ! defined( 'WRL_HOOK_URL' ) ) {
		return;
	}
	if ( ! is_post_type_viewable( $post->post_type ) ) {
		return;
	}
	wp_remote_post(
		WRL_HOOK_URL,
		array(
			'blocking' => false,
			'timeout'  => 3,
			'headers'  => array( 'Content-Type' => 'application/json' ),
			'body'     => wp_json_encode( array( 'urls' => array( get_permalink( $post ) ) ) ),
		)
	);
}

Then put the hook URL into wp-config.php, above the line that says "That's all, stop editing!":

define( 'WRL_HOOK_URL', 'https://api.webresourceledger.com/v1/hooks/site/wrlh_YOUR_HOOK_TOKEN' );

WordPress loads the PHP files in wp-content/mu-plugins by itself, so there is nothing to activate. Create the folder if your site doesn't have it. The plugin shows up under Plugins in its own Must-Use list and can't be turned off there, so nobody deactivates the record by accident. WordPress doesn't offer updates for must-use plugins, so the file is yours to maintain. The same code works as a regular plugin if you prefer one.

What it does

WordPress fires transition_post_status on each save of a post, also when the status doesn't change. The function goes on only when the new status is publish, so it runs when a post or page is published, when a published one is updated, and when WordPress publishes a scheduled post. Drafts, private posts and posts moved to the trash send nothing. is_post_type_viewable leaves out post types that have no page of their own, such as menu items.

The body is {"urls": ["https://example.com/2026/11/29/the-post/"]} with the post's permalink. WRL waits 60 seconds and then captures that address, which gives a page cache time to serve the new version. If your cache takes longer, raise the site's hookDelaySeconds (see Set up a site).

With 'blocking' => false WordPress doesn't read WRL's answer. The request is still sent while the post is being saved, and 'timeout' => 3 limits how long a slow connection can delay the save. If one save fires the action twice, WRL skips the second call's page because its capture is already pending.

A new post also changes the home page and its category archives. To capture the home page along with each post, add it to the list:

'body' => wp_json_encode( array( 'urls' => array( get_permalink( $post ), home_url( '/' ) ) ) ),

We ran this file on WordPress 7.1.5 with PHP 8.3. Publishing a post, updating it and publishing a page each sent one call with the right address, and so did a scheduled post when WordPress published it. A draft, a private post, a menu item and a trashed post sent none.


Check that it works

Publish or update a post. About two minutes later it has a new capture:

curl "https://api.webresourceledger.com/v1/captures?host=example.com&limit=5" \
  -H "Authorization: Bearer YOUR_API_KEY"

If nothing arrives, check that the constant in wp-config.php has the whole hook URL and that your server may make outgoing HTTPS requests. A hook URL that was replaced answers 404. The plugin doesn't read the answer, so try the URL with curl -X POST from a terminal. GET /v1/sites/example.com shows when the hook was last called under settings.hook.lastCallAt.