Last active
August 15, 2023 14:04
-
-
Save jameskoster/40a75071cd693b7282e62fe0e7f357da to your computer and use it in GitHub Desktop.
Display featured image as header background
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_action( 'wp_head', 'jk_header_background', 999 ); | |
function jk_header_background() { | |
global $post; | |
$post_thumbnail_id = get_post_thumbnail_id( $post->ID ); | |
$post_thumbnail_url = wp_get_attachment_url( $post_thumbnail_id ); | |
if ( $post_thumbnail_id ) { | |
?> | |
<style> | |
// Replace '.my-header' with your header class. | |
.my-header { | |
background: url(<?php echo $post_thumbnail_url ?>); | |
background-size: cover; | |
} | |
</style> | |
<?php | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment