Skip to content

Instantly share code, notes, and snippets.

@jshwlkr
Last active February 9, 2022 15:45
Show Gist options
  • Save jshwlkr/dcaf108f594c310693158b8bbfad8caf to your computer and use it in GitHub Desktop.
Save jshwlkr/dcaf108f594c310693158b8bbfad8caf to your computer and use it in GitHub Desktop.
Scan your WordPress content for (anything) a URL and then insert some prefetch hint etc into the head element.
function prefix_filter_embeds( $content ) {
if strpos( $content, 'string' ) !== false ) {
add_action( 'wp_head', 'prefix_url_actions', 0 );
}
return $content;
}
add_filter( 'the_content', 'prefix_filter_embeds' );
function prefix_url_actions() {
echo '<link rel="prefetch" href="" crossorigin>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment