Change the subject or body of the Link Health email digest, or skip one
benecaster_outlinks_health_digest_subject and benecaster_outlinks_health_digest_body run only when a digest is about to be sent: at the end of a finished check, when the digest frequency has passed, something has broken that the last digest did not report, and the site’s admin email is a valid address. The subject filter runs first, then the body filter, then the email is sent.
$new_items are the newly broken items, in the shape described in Run your own code when a Link Health check finishes; $total_broken is how many items are broken in all. The default body lists at most 50 of $new_items, then a count.
- Subject: the return is trimmed and used. A return that is not a string, or is empty once trimmed, keeps the default (“Link Health: 3 newly broken links or images on {site name}”).
- Body: raw HTML, sent as returned, so escape every value you add (
esc_html(),esc_url()). A return that is not a string keeps the default.
Code
<?php
add_filter( 'benecaster_outlinks_health_digest_body', function ( string $html, array $new_items, int $total_broken ): string {
// Only email about tracked links; image and page-link breakages wait for the Link Health page.
$redirects = array_filter( $new_items, fn( array $item ): bool => 'redirect' === $item['kind'] );
if ( [] === $redirects ) {
return '';
}
return $html . '<p>' . esc_html__( 'Fix tracked links first: they are in your show notes.', 'my-plugin' ) . '</p>';
}, 10, 3 );
Hooks Used
Need this built rather than just documented? See our services →