Web Hosting Geeks | Web Hosting Experts
Need help? Call us 1(866)TOP-HOST

14655 reviews 1734 hosting providers

Questions & Answers

Wordpress Image Header for Each Post

Aug 16, 2012 by SunFun
Hi there

I am trying to create a customized field where visitors can add images as headers for posts. I want it to work such as if there are no images to be added, the post should follow the standard title header.
Any help will be appreciated

Many thanks

2 Answers

0 votes
Aug 18, 2012 by WebProX
Try setting the header image as a featured image in a post and add the following code under your page template:

global $post;
$post_thumbnail_id = get_post_meta($post->ID, 'featured_image', true);
if ($post_thumbnail_id > 0) {
$attachment =& get_post($post_thumbnail_id);
echo '<img src="' . $attachment->guid . '" alt="" />';
Then you can display details of post individually.
0 votes
Aug 18, 2012 by WebGuru
if ( haspost_thumbnail() ) {
<h2 class="title"><?php the_title(); ?></h2>