WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have recreated it in Wordpress and am working offline. Everything is good and works the way I want it to. I have does this in order to add a blog. To get the image above the content I used custom fields. When the blog page is a static page it works fine but when I set it be the post page the image does not show up. The container for the image shows up, just not the image. Here is the code for the beginning of the single.php and index.php up until the loop starts.

       get_sidebar(); ?>


        $image = get_post_meta($post->ID, img, true);

        <img src="<?php echo $image; ?>" class="img"/>


<div id="content" class="narrowcolumn" role="main">

<?php if (have_posts()) : ?>

    <?php while (have_posts()) : the_post(); ?>

I have read a few things about calling the custom field outside the loop but I'm not sure how to do this or if that is even correct. Any help would be greatly appreciated.

share|improve this question

This is pretty wonky (I would never do it), but it should work if you access the global.

    global $post;
    $image = get_post_meta( $wp_query->post->ID, 'img', true);

    <img src="<?php echo $image; ?>" class="img"/>
share|improve this answer
Can't you use global $post instead of global $wp_query then use get_post_meta ? – BandonRandon Jul 5 '13 at 8:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.