DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

In a few days, WordPress 2.9 will be released. This all new version feature a bunch of interesting functions to display an image attached to a post.

Paste the following code, within the loop, where you want to post image to be displayed.

	if (  (function_exists('has_post_image')) && (has_post_image())  ) {
	} else {
		$postimageurl = get_post_meta($post->ID, 'post-image', true);
		if ($postimageurl) { 
			echo '<img src="'.$postimageurl.'" alt="" />';

What this code do :
-First, it makes sure that the has_post_image() function exists and that the current post have an image attached. If both conditions are true, the post image is displayed using WordPress 2.9 function the_post_image().
-If not, the get_post_meta() function is used to get the value of the custom field which contain the post image.

Leave a Comment

Your email address will not be published. Required fields are marked *