Skip to content

Instantly share code, notes, and snippets.

@iparamonau
Created August 26, 2015 12:22
Show Gist options
  • Select an option

  • Save iparamonau/64bf07527d66ec0b9cff to your computer and use it in GitHub Desktop.

Select an option

Save iparamonau/64bf07527d66ec0b9cff to your computer and use it in GitHub Desktop.
WordPress: wrap embed HTML with the domain specific class
add_filter( 'embed_oembed_html', 'domain_class_oembed_filter', 10, 2) ;
function domain_class_oembed_filter($html, $url) {
$domain = preg_replace( '#www\.|\.com#i', '', parse_url($url, PHP_URL_HOST));
return '<div class="iframely '.$domain.'">'.$html.'</div>';
}
@espi
Copy link
Copy Markdown

espi commented Sep 8, 2015

Use the full hostname and a sub-class for more harderer code.

add_filter( 'embed_oembed_html', 'domain_class_oembed_filter', 10, 2) ;

function domain_class_oembed_filter($html, $url) {
    $domain = preg_replace( '#[^a-zA-Z0-9]#i', '', parse_url($url, PHP_URL_HOST));
    return '<div class="iframely iframely-'.$domain.'">'.$html.'</div>';
}

@iparamonau
Copy link
Copy Markdown
Author

@espi 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment