The following examples use hooks documented on this site. Add them to wp-content/mu-plugins/staticscope-hooks.php and adjust the names and addresses for your site. None require a fork. If a recipe needs a hook that is not here, check the actions and filters references first.
Test on staging before production. A hook that throws stops a publish, which is the point, but a bug in the same hook stops every publish. Keep each snippet small and log the values you are about to compare.
1. Log every build
You want a record outside the Activity log, with a start and an end you can grep. Hook the build request and the end of preparation.
add_action( 'staticscope_before_build', function () {
error_log( 'StaticScope: build started' );
} );
add_action( 'staticscope_post_process_complete', function ( string $dir ) {
error_log( 'StaticScope: build finished at ' . gmdate( 'c' ) . ' in ' . $dir );
}, 30 );
staticscope_post_process_complete is the end of preparation, not the end of publishing. Add staticscope_post_deploy_trigger if you want the publish in the same log. If you only care about releases, move the end marker there and accept that a build without a publish leaves no closing line. A scheduled or WP-CLI build also skips the start line, because staticscope_before_build only fires from the Overview.
2. Block a publish when a post has no excerpt
Excerpts feed the meta descriptions and the archive cards. A missing one should stop the publish, not get noticed a week later.
add_action( 'staticscope_before_publish', function () {
$posts = get_posts( [
'post_type' => 'post',
'post_status' => 'publish',
'numberposts' => -1,
] );
foreach ( $posts as $post ) {
if ( trim( (string) $post->post_excerpt ) === '' ) {
throw new RuntimeException( 'Add an excerpt to "' . $post->post_title . '".' );
}
}
} );
The exception message appears in the Overview. This covers the Overview and the three official publishers. wp staticscope deploy does not fire the hook, so add the same check to staticscope_deploy at priority 9 if CLI publishes must be gated too.
3. Rewrite an asset URL in prepared pages
A plugin hard-codes a CDN host you no longer use. The URL rewriter only handles site addresses, so patch the HTML on its way out.
add_action( 'staticscope_process_html', function ( string $file ) {
$html = file_get_contents( $file );
if ( $html === false ) {
return;
}
$html = str_replace( 'https://cdn.old.example.com/', '/assets/', $html );
file_put_contents( $file, $html );
} );
This changes the prepared copy only; the files copied from WordPress are untouched. Keep the replacement root-relative so it works on any domain. If the same URL appears in stylesheets, add a staticscope_process_css callback with the same replacement.
4. Exclude a path from the crawl
You have a members area that should never reach the static site. Remove it after detection, and stop the crawler discovering it again.
add_filter( 'staticscope_modify_initial_crawl_list', function ( array $urls ) {
return array_values( array_filter( $urls, function ( string $url ) {
return ! str_starts_with( $url, '/members/' );
} ) );
} );
add_filter( 'staticscope_discovered_paths', function ( array $paths ) {
return array_values( array_filter( $paths, function ( string $path ) {
return ! str_starts_with( $path, '/members/' );
} ) );
} );
The first filter prunes what detection found. The second stops a link in another page adding it back during the crawl. For a permanent rule, add /members/* to Pages to leave out on the Settings screen as well.
5. Send completion email somewhere else in staging
You do not want staging builds emailing the client. Filter the option instead of editing the saved setting, so the value returns to normal when you remove the snippet.
add_filter( 'staticscope_option_completionEmail', function ( $value ) {
if ( wp_get_environment_type() === 'staging' ) {
return 'staging@example.com';
}
return $value;
} );
Option filters run on read. Nothing is written to wp_options, and the filter also applies to the failure email. Do not use this to paper over a broken setting: if production also needs a different address, change the setting itself.
6. Raise crawl concurrency on the command line
A local machine or a build runner can copy more files at once than a shared host. Raise the limit only where it is safe.
add_filter( 'staticscope_option_crawlConcurrency', function ( $value ) {
if ( defined( 'WP_CLI' ) && WP_CLI ) {
return '12';
}
return $value;
} );
The crawler enforces a minimum of 1. Twelve is a reasonable ceiling for a build runner; going higher mostly adds memory pressure and timeouts, not speed. The value is read during the copy phase, so it also applies to jobs that run from the queue.
7. Post a Slack message after deploy
The team wants to know what went live without opening the admin. Use the post-deploy action and guard the optional detail array.
add_action( 'staticscope_post_deploy_trigger', function ( string $deployer, array $details = [] ) {
$address = $details['addresses']['Production'] ?? home_url( '/' );
wp_remote_post( 'https://hooks.slack.com/services/T000/B000/XXXX', [
'timeout' => 5,
'body' => [ 'text' => 'Published ' . $address . ' with ' . $deployer ],
] );
}, 10, 2 );
Core calls this with one argument, so the default on $details is required. GitHub is the publisher that supplies summary and addresses.
8. Change the media cap in Sync
Your PDFs are 30 MB and Sync stops at 25 MB. Raise the cap, but keep the repository or object store in mind.
add_filter( 'staticscope_sync_media_max_bytes', function () {
return 50 * 1024 * 1024;
} );
Files over the cap stay local and are counted as skipped. Set the same cap on every site in the team, or a file accepted by one site can be refused by another. The check happens before the file is read, so raising the cap is cheap; what costs time and repository space is the file itself.
9. Carry a custom field through Sync
You store a reading time in post meta and want it on every site. Export it into the document, then read it back on import. Unknown keys survive the merge.
add_filter( 'staticscope_sync_exported_document', function ( array $doc, WP_Post $post ) {
$doc['reading_time'] = (int) get_post_meta( $post->ID, 'reading_time', true );
return $doc;
}, 10, 2 );
add_filter( 'staticscope_sync_imported_document', function ( array $doc ) {
if ( ! isset( $doc['reading_time'], $doc['id'] ) ) {
return $doc;
}
$post_id = \StaticScopeSync\Content\Importer::find( (string) $doc['id'] );
if ( $post_id > 0 ) {
update_post_meta( $post_id, 'reading_time', (int) $doc['reading_time'] );
}
return $doc;
} );
On a first import there is no local post yet, so the meta write is skipped. The next push exports the field again and the value settles. Keep the key stable: changing it later leaves the old value in existing documents under the old name.
10. Fail the build on a broken link
DeadLinks normally removes missing links at priority 20. You would rather fail the build and fix the source. Run before it and throw with the path.
add_action( 'staticscope_post_process_complete', function ( string $dir ) {
$html = file_get_contents( $dir . '/index.html' );
if ( $html === false ) {
return;
}
preg_match_all( '/href="(\/[^"#?]*)/', $html, $matches );
foreach ( array_unique( $matches[1] ) as $path ) {
if ( $path === '/' || str_starts_with( $path, '//' ) ) {
continue;
}
$target = $dir . '/' . ltrim( $path, '/' );
if ( file_exists( $target ) || file_exists( rtrim( $target, '/' ) . '/index.html' ) ) {
continue;
}
throw new RuntimeException( 'Broken link in the home page: ' . $path );
}
}, 15 );
Priority 15 runs before DeadLinks, which is the point: at 20 the evidence has already been removed. This checks the home page only. Wrap the file read and the loop in a list of HTML files if you want the whole site, and expect false positives on links built by JavaScript.
If you only want a warning, log the path instead of throwing. Do not remove the check because one page has a false positive; narrow it to the links you own.