Last active
August 29, 2015 14:17
-
-
Save SiGaCode/091ec8e4cc6e589bbb1f to your computer and use it in GitHub Desktop.
Use different featured images as a body background for different pages
Credits: https://journalxtra.com/wordpress/quicksnips/use-wordpress-featured-image-post-page-background-picture/
You can set a "default" body background image in Dynamik Design - Body. It will be displayed when no featured image available.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//*https://journalxtra.com/wordpress/quicksnips/use-wordpress-featured-image-post-page-background-picture/ | |
add_action( 'wp_head', 'vr_set_featured_background', 99); | |
function vr_set_featured_background() { | |
$image_url = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), full, false ); | |
if ($image_url[0]) { | |
//* Close php tag for body styles | |
?> | |
<style> | |
body { | |
background:url(<?php echo $image_url[0]; ?>) #fff fixed center top no-repeat; | |
} | |
/* Uncomment if the image hangs low in a Genesis theme */ | |
/*.site-inner { | |
padding-top:0!important; | |
padding-bottom:0!important; | |
}*/ | |
</style> | |
<?php | |
//* Open php tag again for rest of functions | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Add this to custom CSS */ | |
/* The following is a fix for some mobile browsers */ | |
html,body { | |
height:100%; | |
min-height:100%; | |
margin:0!important; | |
} | |
body { | |
-webkit-background-size: cover; | |
-moz-background-size: cover; | |
-o-background-size: cover; | |
background-size: cover; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment