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?


1 Answer 1


The $page_id variable wasn't defined in category.php so I changed as seen below:

$background_image = get_post_meta( $post->ID, 'mb_background_image', true );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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