custom-header.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Implement Custom Headers for the site
  4. *
  5. * @package Libretto
  6. */
  7. /**
  8. * Set up the WordPress core custom header feature.
  9. *
  10. * @uses libretto_header_style()
  11. * @uses libretto_admin_header_style()
  12. * @uses libretto_admin_header_image()
  13. */
  14. function libretto_custom_header_setup() {
  15. add_theme_support( 'custom-header', apply_filters( 'libretto_custom_header_args', array(
  16. 'default-image' => '',
  17. 'default-text-color' => 'faf9f5',
  18. 'width' => 1600,
  19. 'height' => 275,
  20. 'flex-height' => true,
  21. 'flex-width' => true,
  22. 'wp-head-callback' => 'libretto_header_style',
  23. ) ) );
  24. }
  25. add_action( 'after_setup_theme', 'libretto_custom_header_setup' );
  26. if ( ! function_exists( 'libretto_header_style' ) ) :
  27. /**
  28. * Styles the header image and text displayed on the blog
  29. *
  30. * @see libretto_custom_header_setup().
  31. */
  32. function libretto_header_style() {
  33. $header_text_color = get_header_textcolor();
  34. $header_image = libretto_get_header_image();
  35. // If no custom options for text are set, and there's no custom header, return early.
  36. // get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value
  37. if ( HEADER_TEXTCOLOR === $header_text_color AND ! isset( $header_image ) ) {
  38. return;
  39. }
  40. // If we get this far, we have custom styles. Let's do this.
  41. ?>
  42. <style type="text/css">
  43. <?php if ( 'blank' === $header_text_color ) : // Hide text if user has set to hide ?>
  44. .site-title,
  45. .site-description {
  46. position: absolute;
  47. clip: rect(1px, 1px, 1px, 1px);
  48. }
  49. <?php endif; ?>
  50. <?php if ( HEADER_TEXTCOLOR !== $header_text_color ) : // Only apply custom header colour if not default ?>
  51. .title-block .site-title a,
  52. .header-image .title-block .site-title a,
  53. .title-block .site-description,
  54. .header-image .title-block .site-description {
  55. color: #<?php echo esc_attr( $header_text_color ); ?>;
  56. }
  57. <?php endif; ?>
  58. <?php if ( isset( $header_image ) ) : // Show our custom header image if one exists ?>
  59. .libretto-has-header-image #masthead {
  60. background-image: url('<?php echo esc_url( $header_image ); ?>');
  61. }
  62. <?php endif; ?>
  63. </style>
  64. <?php
  65. } // libretto_header_style()
  66. endif;