-
-
Save zzap/827c34cf84c5dfef0230a3315805fe3b to your computer and use it in GitHub Desktop.
Set aspect ratio for the iframe with WP_HTML_Tag_Processor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Set aspect ratio for the iframe. | |
*/ | |
$tags = new WP_HTML_Tag_Processor( $html ); | |
if ( $tags->next_tag( 'iframe' ) ) { | |
$width = $tags->get_attribute( 'width' ); | |
$height = $tags->get_attribute( 'height' ); | |
$style = $tags->get_attribute( 'style' ); | |
$tags->set_attribute( 'width', '100%' ); | |
$tags->remove_attribute( 'height' ); | |
$tags->set_attribute( 'style', $style . "; aspect-ratio: {$width}/{$height};" ); | |
} | |
echo $tags->get_updated_html(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment