I have this piece of code which inserts a featured image into the header of a page/post similar to the http://medium.com blog layout.
<?php
if (has_post_thumbnail()) { //if a thumbnail has been set
$imgID = get_post_thumbnail_id($post->ID); //get the id of the featured image
$featuredImage = wp_get_attachment_image_src($imgID, 'full' );//get the url of the featured image (returns an array)
$imgURL = $featuredImage[0]; //get the url of the image out of the array
?>
<style>
.header-image {
border:none;
color:black;
background-image:url('<?php echo $imgURL ?>');
background-size: cover;
width: 100%;
height: 450px;
}
</style>
<?php
}//end if
?>
The only file I can think to place this code into (and where it works) is head.php, but I would rather not have styles in the head tags. Is there an appropriate way to insert CSS that contains pHp? Thanks in advance.
By the way, have you actually looked at the source of medium’s header images? They control stuff like shading and gradient overlays via URL params. Very very cool.