custom-header.php 2.1 KB

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