custom-header.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. /**
  3. * @package Spun
  4. */
  5. /**
  6. * Setup the WordPress core custom header feature.
  7. *
  8. * @uses spun_header_style()
  9. * @uses spun_admin_header_style()
  10. * @uses spun_admin_header_image()
  11. *
  12. * @package Spun
  13. */
  14. function spun_custom_header_setup() {
  15. $args = array(
  16. 'default-image' => '',
  17. 'default-text-color' => '999999',
  18. 'width' => 150,
  19. 'height' => 150,
  20. 'flex-width' => true,
  21. 'flex-height' => true,
  22. 'wp-head-callback' => 'spun_header_style',
  23. 'admin-head-callback' => 'spun_admin_header_style',
  24. 'admin-preview-callback' => 'spun_admin_header_image',
  25. );
  26. $args = apply_filters( 'spun_custom_header_args', $args );
  27. add_theme_support( 'custom-header', $args );
  28. }
  29. add_action( 'after_setup_theme', 'spun_custom_header_setup' );
  30. if ( ! function_exists( 'spun_header_style' ) ) :
  31. /**
  32. * Styles the header image and text displayed on the blog
  33. *
  34. * @see spun_custom_header_setup().
  35. *
  36. */
  37. function spun_header_style() {
  38. $header_text_color = get_header_textcolor();
  39. // If no custom options for text are set, let's bail
  40. // get_header_textcolor() options: HEADER_TEXTCOLOR is default, hide text (returns 'blank') or any hex value
  41. if ( HEADER_TEXTCOLOR == $header_text_color )
  42. return;
  43. // If we get this far, we have custom styles. Let's do this.
  44. ?>
  45. <style type="text/css">
  46. <?php
  47. // Has the text been hidden?
  48. if ( 'blank' == $header_text_color ) :
  49. ?>
  50. .site-title,
  51. .site-description {
  52. position: absolute;
  53. clip: rect(1px, 1px, 1px, 1px);
  54. }
  55. <?php
  56. // If the user has set a custom color for the text use that
  57. else :
  58. ?>
  59. .site-title a,
  60. .site-description {
  61. color: #<?php echo $header_text_color; ?>;
  62. }
  63. <?php endif; ?>
  64. </style>
  65. <?php
  66. }
  67. endif; // spun_header_style
  68. if ( ! function_exists( 'spun_admin_header_style' ) ) :
  69. /**
  70. * Styles the header image displayed on the Appearance > Header admin panel.
  71. *
  72. * @see spun_custom_header_setup().
  73. *
  74. */
  75. function spun_admin_header_style() {
  76. ?>
  77. <style type="text/css">
  78. <?php if ( false == get_theme_mod( 'spun_opacity', false ) ) : ?>
  79. .header-img-wrapper {
  80. opacity: .3;
  81. transition: opacity .5s ease-in-out;
  82. -webkit-transition: opacity .5s ease-in-out;
  83. -moz-transition: opacity .5s ease-in-out;
  84. -o-transition: opacity .5s ease-in-out;
  85. }
  86. <?php endif; ?>
  87. .appearance_page_custom-header #headimg {
  88. background: #fff;
  89. border: none;
  90. box-sizing: border-box;
  91. padding: 30px 1.5em;
  92. }
  93. .site-branding {
  94. display: inline-block;
  95. vertical-align: sub;
  96. }
  97. .appearance_page_custom-header #headimg:hover .header-img-wrapper {
  98. opacity: 1;
  99. transition: opacity .5s ease-in-out;
  100. -webkit-transition: opacity .5s ease-in-out;
  101. -moz-transition: opacity .5s ease-in-out;
  102. -o-transition: opacity .5s ease-in-out;
  103. }
  104. #headimg h1,
  105. #desc {
  106. }
  107. #headimg h1 {
  108. float: left;
  109. font-family: Playfair, Baskerville, "Times New Roman", Times, serif;
  110. font-size: 24px;
  111. font-style: italic;
  112. font-weight: normal;
  113. line-height: 1;
  114. margin: 0;
  115. text-transform: none;
  116. vertical-align: middle;
  117. }
  118. #headimg h1 a {
  119. text-decoration: none;
  120. }
  121. #desc {
  122. clear: none;
  123. display: none;
  124. font-family: Quicksand, Helvetica, Arial, sans-serif;
  125. -webkit-text-stroke: .35px; /* Hack to fix thin text in Windows */
  126. font-size: 14px;
  127. font-style: normal;
  128. margin: .75em 0;
  129. text-transform: uppercase;
  130. }
  131. #headimg img {
  132. display: inline-block;
  133. margin-right: 16px;
  134. margin-bottom: 0;
  135. max-width: 100%;
  136. vertical-align: middle;
  137. }
  138. .header-img-wrapper {
  139. float: left;
  140. width: 450px;
  141. }
  142. </style>
  143. <?php
  144. }
  145. endif; // spun_admin_header_style
  146. if ( ! function_exists( 'spun_admin_header_image' ) ) :
  147. /**
  148. * Custom header image markup displayed on the Appearance > Header admin panel.
  149. *
  150. * @see spun_custom_header_setup().
  151. *
  152. */
  153. function spun_admin_header_image() { ?>
  154. <div id="headimg">
  155. <div class="header-img-wrapper">
  156. <?php $header_image = get_header_image();
  157. if ( ! empty( $header_image ) ) : ?>
  158. <img src="<?php echo esc_url( $header_image ); ?>" alt="" />
  159. <?php endif; ?>
  160. <div class="site-branding">
  161. <?php $style = sprintf( ' style="color:#%s;"', get_header_textcolor() ); ?>
  162. <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>
  163. <div id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></div>
  164. </div>
  165. </div>
  166. </div>
  167. <?php }
  168. endif; // spun_admin_header_image