I need to get the featured image outside the loop. This is so that I can have a different full-screen background image for each page, set by the featured image.
After doing some research I was able to get the post ID outside the loop.
This is what I've got:
$page_object = get_queried_object();
$page_id = get_queried_object_id();
$bkgdImg = wp_get_attachment_url( $page_id );
if (!empty($bkgdImg)) {
$backgroundImg = $bkgdImg;
}
else {
$defaultbackground = . get_template_directory_uri() . "/images/default-background.jpg";
$backgroundImg = $defaultBackground;
}
echo $backgroundImg;
Thanks!