header-image.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <div class="custom-header">
  2. <?php
  3. $header_image = get_header_image();
  4. $jetpack_portfolio_featured_image = get_option( 'jetpack_portfolio_featured_image' );
  5. // If this is a single post or page with a featured image (but not a portfolio)
  6. if ( has_post_thumbnail() && ( is_singular() && 'jetpack-portfolio' !== get_post_type() && lodestar_jetpack_featured_image_display() ) ) :
  7. $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
  8. $thumbnail_attributes = wp_get_attachment_image_src( $post_thumbnail_id, 'lodestar-featured-image' );
  9. ?>
  10. <div class="custom-header-image" style="background-image: url(<?php echo esc_url( $thumbnail_attributes[0] ); ?>)">
  11. <?php get_template_part( 'components/header/site', 'branding' ); ?>
  12. </div>
  13. <?php
  14. // Else if this is a portfolio archive, and the Portfolio featured image is set
  15. // TODO: Decide if this image should also be shown for Portfolio types and tags archives
  16. elseif (
  17. ( is_post_type_archive( 'jetpack-portfolio' ) || is_tax( 'jetpack-portfolio-type' ) || is_tax( 'jetpack-portfolio-tag') || 'jetpack-portfolio' === get_post_type() ) && isset( $jetpack_portfolio_featured_image ) && '' != $jetpack_portfolio_featured_image ) :
  18. $featured_image_attributes = wp_get_attachment_image_src( $jetpack_portfolio_featured_image, 'lodestar-featured-image' ); ?>
  19. <div class="custom-header-image" style="background-image: url(<?php echo esc_url( $featured_image_attributes[0] ); ?>)">
  20. <?php get_template_part( 'components/header/site', 'branding' ); ?>
  21. </div>
  22. <?php
  23. // Else if the Custom Header image has been set
  24. elseif ( ! empty( $header_image ) ) : ?>
  25. <div class="custom-header-image" style="background-image: url(<?php echo esc_url( $header_image ); ?>)">
  26. <?php get_template_part( 'components/header/site', 'branding' ); ?>
  27. </div>
  28. <?php
  29. // Otherwise, show an empty header background.
  30. else : ?>
  31. <div class="custom-header-image">
  32. <?php get_template_part( 'components/header/site', 'branding' ); ?>
  33. </div>
  34. <?php endif; ?>
  35. </div><!-- .custom-header -->