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'm referencing an attached image in my header.php page which is displayed as a full screen background on my posts:

global $wp_query;
$page_id = $wp_query->get_queried_object_id();
$background_image = get_post_meta($page_id, 'mb_background_image', true);
$src = wp_get_attachment_image_src($background_image, 'full');

This works fine on single posts, but doesn't work when displaying just one post per page in category.php.

How can I fix this?


share|improve this question
up vote 0 down vote accepted

The $page_id variable wasn't defined in category.php so I changed it to this.

$background_image = get_post_meta($post->ID, 'mb_background_image', true);
share|improve this answer

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.