custom-header.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 UIU_CSE
  12. */
  13. /**
  14. * Set up the WordPress core custom header feature.
  15. *
  16. * @uses uiu_cse_header_style()
  17. */
  18. function uiu_cse_custom_header_setup() {
  19. add_theme_support(
  20. 'custom-header',
  21. apply_filters(
  22. 'uiu_cse_custom_header_args',
  23. array(
  24. 'default-image' => '',
  25. 'default-text-color' => '000000',
  26. 'width' => 1000,
  27. 'height' => 250,
  28. 'flex-height' => true,
  29. 'wp-head-callback' => 'uiu_cse_header_style',
  30. )
  31. )
  32. );
  33. }
  34. add_action( 'after_setup_theme', 'uiu_cse_custom_header_setup' );
  35. if ( ! function_exists( 'uiu_cse_header_style' ) ) :
  36. /**
  37. * Styles the header image and text displayed on the blog.
  38. *
  39. * @see uiu_cse_custom_header_setup().
  40. */
  41. function uiu_cse_header_style() {
  42. $header_text_color = get_header_textcolor();
  43. /*
  44. * If no custom options for text are set, let's bail.
  45. * get_header_textcolor() options: Any hex value, 'blank' to hide text. Default: add_theme_support( 'custom-header' ).
  46. */
  47. if ( get_theme_support( 'custom-header', 'default-text-color' ) === $header_text_color ) {
  48. return;
  49. }
  50. // If we get this far, we have custom styles. Let's do this.
  51. ?>
  52. <style type="text/css">
  53. <?php
  54. // Has the text been hidden?
  55. if ( ! display_header_text() ) :
  56. ?>
  57. .site-title,
  58. .site-description {
  59. position: absolute;
  60. clip: rect(1px, 1px, 1px, 1px);
  61. }
  62. <?php
  63. // If the user has set a custom color for the text use that.
  64. else :
  65. ?>
  66. .site-title a,
  67. .site-description {
  68. color: #<?php echo esc_attr( $header_text_color ); ?>;
  69. }
  70. <?php endif; ?>
  71. </style>
  72. <?php
  73. }
  74. endif;