diff --git a/classes/Webp/Picture/Display.php b/classes/Webp/Picture/Display.php index b1c03d30e..d9b55bc0d 100644 --- a/classes/Webp/Picture/Display.php +++ b/classes/Webp/Picture/Display.php @@ -192,7 +192,7 @@ protected function build_picture_tag( $image ) { */ $attributes = apply_filters( 'imagify_picture_attributes', $attributes, $image ); - $output = 'build_attributes( $attributes ) . ">\n"; + $output = 'build_attributes( $attributes, 'picture' ) . ">\n"; /** * Allow to add more tags to the tag. * @@ -273,7 +273,7 @@ protected function build_source_tag( $image ) { */ $attributes = apply_filters( 'imagify_picture_source_attributes', $attributes, $image ); - return 'build_attributes( $attributes ) . "/>\n"; + return 'build_attributes( $attributes, 'source' ) . "/>\n"; } /** @@ -310,7 +310,7 @@ protected function build_img_tag( $image ) { */ $attributes = apply_filters( 'imagify_picture_img_attributes', $attributes, $image ); - return 'build_attributes( $attributes ) . "/>\n"; + return 'build_attributes( $attributes, 'img' ) . "/>\n"; } /** @@ -323,15 +323,27 @@ protected function build_img_tag( $image ) { * @param array $attributes A list of attribute pairs. * @return string HTML attributes. */ - protected function build_attributes( $attributes ) { + protected function build_attributes( $attributes, $type = false ) { if ( ! $attributes || ! is_array( $attributes ) ) { return ''; } $out = ''; + $css = array(); foreach ( $attributes as $attribute => $value ) { $out .= ' ' . $attribute . '="' . esc_attr( $value ) . '"'; + + if( $attribute === "width" || $attribute === "height" ) { $css[] = $attribute . ':' . $value .'px'; } + + } + + if( $type && $type === "picture" && !empty($css) ) { + + $css = implode(';', $css); + + $out .= ' style="' . $css . ';"'; + } return $out;