seredniy
11/27/2018 - 9:41 AM

Wordpress image helper with alt, title, classes and kama thumbnail

Wordpress image helper with alt, title, classes and kama thumbnail

<?php
/**
 * Display image with all attributes
 * Function uses Kama Thumbnail plugin to crope images
 *
 * @param int    $id        attachment id
 * @param string $kama_args string of arguments for kama_thumbnail
 * @param string $classes   list of classes separated by space
 * @param string $alt       custom alt for image
 * @param string $title     custom title for image
 */
function scf_kama_image( $id, $kama_args = "w=100 &h=100", $classes = "", $alt = "", $title = "" ) {
	$image_id      = ( $id ) ? $id : get_the_ID();
	$image         = get_post( $image_id );
	$image_url     = kama_thumb_src( $kama_args, $image_id );
	$image_alt     = ( $alt ) ? $alt : get_post_meta( $image_id, '_wp_attachment_image_alt', true );
	$image_title   = ( $title ) ? $title : $image->post_title;
	$image_classes = ( $classes ) ? $classes : "scf_image";

	echo "<img src='$image_url' class='$image_classes' alt='$image_alt' title='$image_title'>";
}
?>