Advertisement
fauzanjeg

JKIT || Fix ALT issue on images

Jun 25th, 2023
994
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.37 KB | None | 0 0
  1. /**
  2.      * Build image element from given setting
  3.      *
  4.      * @param array  $attr Image options.
  5.      * @param string $image_size Image size.
  6.      * @param string $additional_id ID.
  7.      * @param string $additional_class Class.
  8.      * @param string $additional_alt Alt.
  9.      *
  10.      * @return string
  11.      */
  12.     protected function render_image_element( $attr, $image_size = 'thumbnail', $additional_id = null, $additional_class = null, $additional_alt = null ) {
  13.         $id         = ! empty( $additional_id ) ? ' id="' . $additional_id . '"' : '';
  14.         $class      = ! empty( $additional_class ) ? ' class="' . $additional_class . '"' : '';
  15.         $alt        = ! empty( $additional_alt ) ? ' alt="' . $additional_alt . '"' : ( isset( $attr['alt'] ) && ! empty( $attr['alt'] ) ? ' alt="' . $attr['alt'] . '"' : '' );
  16.         $width      = ! empty( $attr['width'] ) ? ' width="' . $attr['width'] . '"' : '';
  17.         $height     = ! empty( $attr['height'] ) ? ' height="' . $attr['height'] . '"' : '';
  18.         $attachment = ! empty( $attr['id'] ) ? wp_get_attachment_image_src( $attr['id'], $image_size ) : '';
  19.         $image      = ! empty( $attachment[0] ) ? '<img src="' . esc_url( $attachment[0] ) . '" ' . $id . $class . $alt . $width . $height . '>' : '';
  20.         $image      = ! empty( $attr['url'] ) && empty( $image ) ? '<img src="' . esc_url( $attr['url'] ) . '" ' . $id . $class . $alt . $width . $height . '>' : $image;
  21.  
  22.         return $image;
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement