custom-header.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Sample implementation of the Custom Header feature
  4. *
  5. * You can add an optional custom header image to header.php like so ...
  6. *
  7. <?php the_header_image_tag(); ?>
  8. *
  9. * @link https://developer.wordpress.org/themes/functionality/custom-headers/
  10. *
  11. * @package Photos
  12. */
  13. /**
  14. * Set up the WordPress core custom header feature.
  15. *
  16. * @uses photos_header_style()
  17. */
  18. function photos_custom_header_setup() {
  19. // Custom header support
  20. add_theme_support( 'custom-header', apply_filters( 'photos_custom_header_args', array(
  21. 'default-image' => '',
  22. 'default-text-color' => '111111',
  23. 'width' => 1920,
  24. 'height' => 400,
  25. 'flex-height' => true,
  26. 'flex-width' => true,
  27. 'wp-head-callback' => 'photos_header_style'
  28. ) ) );
  29. }
  30. add_action( 'after_setup_theme', 'photos_custom_header_setup' );
  31. if ( ! function_exists( 'photos_header_style' ) ) :
  32. /**
  33. * Styles the header image and text displayed on the blog.
  34. *
  35. * @see photos_header_style().
  36. */
  37. function photos_header_style() {
  38. $header_text_color = get_header_textcolor();
  39. /*
  40. * If no custom options for text are set, let's bail.
  41. * get_header_textcolor() options: Any hex value, 'blank' to hide text. Default: add_theme_support( 'custom-header' ).
  42. */
  43. if ( get_theme_support( 'custom-header', 'default-text-color' ) === $header_text_color ) {
  44. return;
  45. }
  46. // If we get this far, we have custom styles. Let's do this.
  47. ?>
  48. <style type="text/css">
  49. <?php
  50. // Has the text been hidden?
  51. if ( ! display_header_text() ) :
  52. ?>
  53. .site-title,
  54. .site-description {
  55. position: absolute;
  56. clip: rect(1px, 1px, 1px, 1px);
  57. }
  58. <?php
  59. // If the user has set a custom color for the text use that.
  60. else :
  61. ?>
  62. .site-title a,
  63. .site-description {
  64. color: #<?php echo esc_attr( $header_text_color ); ?>;
  65. }
  66. <?php endif; ?>
  67. </style>
  68. <?php
  69. }
  70. endif;