custom-header.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <?php
  2. /**
  3. * Setup the WordPress core custom header feature.
  4. *
  5. * @uses illustratr_header_style()
  6. * @uses illustratr_admin_header_style()
  7. * @uses illustratr_admin_header_image()
  8. *
  9. * @package Illustratr
  10. */
  11. function illustratr_custom_header_setup() {
  12. add_theme_support( 'custom-header', apply_filters( 'illustratr_custom_header_args', array(
  13. 'default-image' => '',
  14. 'default-text-color' => '24282d',
  15. 'width' => 1100,
  16. 'height' => 250,
  17. 'flex-width' => true,
  18. 'flex-height' => true,
  19. 'wp-head-callback' => 'illustratr_header_style',
  20. 'admin-head-callback' => 'illustratr_admin_header_style',
  21. 'admin-preview-callback' => 'illustratr_admin_header_image',
  22. ) ) );
  23. }
  24. add_action( 'after_setup_theme', 'illustratr_custom_header_setup' );
  25. if ( ! function_exists( 'illustratr_header_style' ) ) :
  26. /**
  27. * Styles the header image and text displayed on the blog
  28. *
  29. * @see illustratr_custom_header_setup().
  30. */
  31. function illustratr_header_style() {
  32. $header_text_color = get_header_textcolor();
  33. // If no custom options for text are set, let's bail
  34. // get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value
  35. if ( HEADER_TEXTCOLOR == $header_text_color ) {
  36. return;
  37. }
  38. // If we get this far, we have custom styles. Let's do this.
  39. ?>
  40. <style type="text/css">
  41. <?php
  42. // Has the text been hidden?
  43. if ( 'blank' == $header_text_color ) :
  44. ?>
  45. .site-title,
  46. .site-description {
  47. position: absolute;
  48. clip: rect(1px, 1px, 1px, 1px);
  49. }
  50. <?php
  51. // If the user has set a custom color for the text use that
  52. else :
  53. ?>
  54. .site-title {
  55. color: #<?php echo $header_text_color; ?>;
  56. }
  57. <?php endif; ?>
  58. </style>
  59. <?php
  60. }
  61. endif; // illustratr_header_style
  62. if ( ! function_exists( 'illustratr_admin_header_style' ) ) :
  63. /**
  64. * Styles the header image displayed on the Appearance > Header admin panel.
  65. *
  66. * @see illustratr_custom_header_setup().
  67. */
  68. function illustratr_admin_header_style() {
  69. ?>
  70. <style type="text/css">
  71. .appearance_page_custom-header #headimg {
  72. border: none;
  73. }
  74. #headimg {
  75. padding: 20px;
  76. background: #fff;
  77. font-size: 1.375em;
  78. text-align: center;
  79. -webkit-box-sizing: border-box;
  80. -moz-box-sizing: border-box;
  81. box-sizing: border-box;
  82. }
  83. #headimg h1,
  84. #desc {
  85. }
  86. #headimg h1 {
  87. margin: 0 0 10px;
  88. font-family: "Source Sans Pro", sans-serif;
  89. font-size: 3.6em;
  90. line-height: 1.1;
  91. font-weight: 900;
  92. text-transform: uppercase;
  93. }
  94. #headimg h1 a {
  95. text-decoration: none;
  96. }
  97. #desc {
  98. color: #b1b2b3 !important;
  99. font-family: "PT Serif", serif;
  100. font-size: 0.73em;
  101. line-height: 1.5;
  102. font-weight: normal;
  103. font-style: italic;
  104. }
  105. #headimg img {
  106. display: block;
  107. margin: 0 auto 20px auto;
  108. }
  109. #headimg img + h1 {
  110. margin-top: -5px;
  111. }
  112. </style>
  113. <?php
  114. }
  115. endif; // illustratr_admin_header_style
  116. if ( ! function_exists( 'illustratr_admin_header_image' ) ) :
  117. /**
  118. * Custom header image markup displayed on the Appearance > Header admin panel.
  119. *
  120. * @see illustratr_custom_header_setup().
  121. */
  122. function illustratr_admin_header_image() {
  123. $style = sprintf( ' style="color:#%s;"', get_header_textcolor() );
  124. ?>
  125. <div id="headimg">
  126. <?php if ( get_header_image() ) : ?>
  127. <img src="<?php header_image(); ?>" alt="">
  128. <?php endif; ?>
  129. <h1 class="displaying-header-text"><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1>
  130. <div class="displaying-header-text" id="desc"><?php bloginfo( 'description' ); ?></div>
  131. </div>
  132. <?php
  133. }
  134. endif; // illustratr_admin_header_image