Skip to content

Instantly share code, notes, and snippets.

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 spacedmonkey/5d080de3711c6964f2d9c92108102523 to your computer and use it in GitHub Desktop.
Save spacedmonkey/5d080de3711c6964f2d9c92108102523 to your computer and use it in GitHub Desktop.
add_filter( 'get_image_tag', function( $html, $id, $alt, $title, $align, $size ){
$original_url = $this->get_original_url( $id );
if ( ! $original_url ) {
return $html;
}
list( $img_src, $width, $height ) = image_downsize( $id, $size );
$hwstring = image_hwstring( $width, $height );
$html = '<img src="' . $img_src . '" alt="' . esc_attr( $alt ) . '" ' . $title . $hwstring . 'class="' . $class . '" />';
return $html;
});
@pierlon
Copy link

pierlon commented Mar 5, 2020

public function get_image_tag( $html, $id, $alt, $title, $align, $size ) {
		// Verify it is an Unsplash ID.
		$original_url = $this->get_original_url( $id );
		if ( ! $original_url ) {
			return $html;
		}

		// Replace img src.
		list( $img_src ) = image_downsize( $id, $size );
		return preg_replace( '/src="([^"]+)"/', "src=\"{$img_src}\"", $html, 1 );
	}

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