Skip to content

Instantly share code, notes, and snippets.

@robertdevore
Created October 19, 2023 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertdevore/335964fb9d85bf7a9ba8ca5bf00080c1 to your computer and use it in GitHub Desktop.
Save robertdevore/335964fb9d85bf7a9ba8ca5bf00080c1 to your computer and use it in GitHub Desktop.
<?php
/**
* Get explicit image sizes
*
* @param string $image_url The image URL - https:// ...
*
* @return string
*/
function get_explicit_image_sizes( $image_url ) {
$img_explicit = '';
if ( $image_url ) {
$logo_media_id = get_media_id_from_url( $image_url );
$img_dimensions = get_image_sizes_by_id( $logo_media_id );
if ( $img_dimensions ) {
$img_explicit = ' width="' . $img_dimensions['width'] . '" height="' . $img_dimensions['height'] . '" ';
}
}
return $img_explicit;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment