Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Converts links to in Gutenberg into embeds
//Gist embeds in Gutenberg, quick fix
//Works if you add links as regular links
add_filter( 'the_content', 'gist_in_gutenberg' );
function gist_in_gutenberg( $content ) {
$doc = new DOMDocument();
foreach ($doc->getElementsByTagName('a') as $link){
$href = $link->getAttribute('href');
if (strpos($href, '') !== false) {
$element = $doc->createElement('script');
$links_to_remove[] = $link;
foreach ($links_to_remove as $link) {
$content = $doc->saveHTML();
return $content;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.