3 * Custom Header functionality for Twenty Fifteen
6 * @subpackage Twenty_Fifteen
7 * @since Twenty Fifteen 1.0
11 * Set up the WordPress core custom header feature.
13 * @uses twentyfifteen_header_style()
15 function twentyfifteen_custom_header_setup() {
16 $color_scheme = twentyfifteen_get_color_scheme();
17 $default_text_color = trim( $color_scheme[4], '#' );
20 * Filter Twenty Fifteen custom-header support arguments.
22 * @since Twenty Fifteen 1.0
24 * @param array $args {
25 * An array of custom-header support arguments.
27 * @type string $default_text_color Default color of the header text.
28 * @type int $width Width in pixels of the custom header image. Default 954.
29 * @type int $height Height in pixels of the custom header image. Default 1300.
30 * @type string $wp-head-callback Callback function used to styles the header image and text
31 * displayed on the blog.
34 add_theme_support( 'custom-header', apply_filters( 'twentyfifteen_custom_header_args', array(
35 'default-text-color' => $default_text_color,
38 'wp-head-callback' => 'twentyfifteen_header_style',
41 add_action( 'after_setup_theme', 'twentyfifteen_custom_header_setup' );
46 * @since Twenty Fifteen 1.0
48 * @param string $color The original color, in 3- or 6-digit hexadecimal form.
49 * @return array Array containing RGB (red, green, and blue) values for the given
50 * HEX code, empty array otherwise.
52 function twentyfifteen_hex2rgb( $color ) {
53 $color = trim( $color, '#' );
55 if ( strlen( $color ) == 3 ) {
56 $r = hexdec( substr( $color, 0, 1 ).substr( $color, 0, 1 ) );
57 $g = hexdec( substr( $color, 1, 1 ).substr( $color, 1, 1 ) );
58 $b = hexdec( substr( $color, 2, 1 ).substr( $color, 2, 1 ) );
59 } else if ( strlen( $color ) == 6 ) {
60 $r = hexdec( substr( $color, 0, 2 ) );
61 $g = hexdec( substr( $color, 2, 2 ) );
62 $b = hexdec( substr( $color, 4, 2 ) );
67 return array( 'red' => $r, 'green' => $g, 'blue' => $b );
70 if ( ! function_exists( 'twentyfifteen_header_style' ) ) :
72 * Styles the header image and text displayed on the blog.
74 * @since Twenty Fifteen 1.0
76 * @see twentyfifteen_custom_header_setup()
78 function twentyfifteen_header_style() {
79 $header_image = get_header_image();
81 // If no custom options for text are set, let's bail.
82 if ( empty( $header_image ) && display_header_text() ) {
86 // If we get this far, we have custom styles. Let's do this.
88 <style type="text/css" id="twentyfifteen-header-css">
90 // Short header for when there is no Custom Header and Header Text is hidden.
91 if ( empty( $header_image ) && ! display_header_text() ) :
102 @media screen and (min-width: 46.25em) {
105 padding-bottom: 21px;
111 @media screen and (min-width: 55em) {
114 padding-bottom: 25px;
120 @media screen and (min-width: 59.6875em) {
132 // Has a Custom Header been added?
133 if ( ! empty( $header_image ) ) :
136 background: url(<?php header_image(); ?>) no-repeat 50% 50%;
137 -webkit-background-size: cover;
138 -moz-background-size: cover;
139 -o-background-size: cover;
140 background-size: cover;
143 @media screen and (min-width: 59.6875em) {
145 background: url(<?php header_image(); ?>) no-repeat 100% 50%;
146 -webkit-background-size: cover;
147 -moz-background-size: cover;
148 -o-background-size: cover;
149 background-size: cover;
154 background: transparent;
160 // Has the text been hidden?
161 if ( ! display_header_text() ) :
165 clip: rect(1px, 1px, 1px, 1px);
172 endif; // twentyfifteen_header_style
175 * Enqueues front-end CSS for the header background color.
177 * @since Twenty Fifteen 1.0
179 * @see wp_add_inline_style()
181 function twentyfifteen_header_background_color_css() {
182 $color_scheme = twentyfifteen_get_color_scheme();
183 $default_color = $color_scheme[1];
184 $header_background_color = get_theme_mod( 'header_background_color', $default_color );
186 // Don't do anything if the current color is the default.
187 if ( $header_background_color === $default_color ) {
192 /* Custom Header Background Color */
195 background-color: %1$s;
198 @media screen and (min-width: 59.6875em) {
201 background-color: transparent;
205 .widget input[type="button"],
206 .widget input[type="reset"],
207 .widget input[type="submit"],
208 .widget_calendar tbody a,
209 .widget_calendar tbody a:hover,
210 .widget_calendar tbody a:focus {
216 wp_add_inline_style( 'twentyfifteen-style', sprintf( $css, $header_background_color ) );
218 add_action( 'wp_enqueue_scripts', 'twentyfifteen_header_background_color_css', 11 );
221 * Enqueues front-end CSS for the sidebar text color.
223 * @since Twenty Fifteen 1.0
225 function twentyfifteen_sidebar_text_color_css() {
226 $color_scheme = twentyfifteen_get_color_scheme();
227 $default_color = $color_scheme[4];
228 $sidebar_link_color = get_theme_mod( 'sidebar_textcolor', $default_color );
230 // Don't do anything if the current color is the default.
231 if ( $sidebar_link_color === $default_color ) {
235 // If we get this far, we have custom styles. Let's do this.
236 $sidebar_link_color_rgb = twentyfifteen_hex2rgb( $sidebar_link_color );
237 $sidebar_text_color = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.7)', $sidebar_link_color_rgb );
238 $sidebar_border_color = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.1)', $sidebar_link_color_rgb );
239 $sidebar_border_focus_color = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.3)', $sidebar_link_color_rgb );
242 /* Custom Sidebar Text Color */
245 .secondary-toggle:before {
250 .site-title a:focus {
251 color: %1$s; /* Fallback for IE7 and IE8 */
256 border-color: %1$s; /* Fallback for IE7 and IE8 */
260 .secondary-toggle:hover,
261 .secondary-toggle:focus {
262 border-color: %1$s; /* Fallback for IE7 and IE8 */
267 outline-color: %1$s; /* Fallback for IE7 and IE8 */
271 @media screen and (min-width: 59.6875em) {
273 .dropdown-toggle:after,
275 .widget blockquote cite,
276 .widget blockquote small {
281 .widget input[type="button"],
282 .widget input[type="reset"],
283 .widget input[type="submit"],
284 .widget_calendar tbody a {
285 background-color: %1$s;
294 .main-navigation .menu-item-description,
297 .widget .wp-caption-text,
298 .widget .gallery-caption {
302 .widget button:hover,
303 .widget button:focus,
304 .widget input[type="button"]:hover,
305 .widget input[type="button"]:focus,
306 .widget input[type="reset"]:hover,
307 .widget input[type="reset"]:focus,
308 .widget input[type="submit"]:hover,
309 .widget input[type="submit"]:focus,
310 .widget_calendar tbody a:hover,
311 .widget_calendar tbody a:focus {
312 background-color: %2$s;
329 .widget_categories .children,
330 .widget_nav_menu .sub-menu,
331 .widget_pages .children,
332 .widget abbr[title] {
336 .dropdown-toggle:hover,
337 .dropdown-toggle:focus,
339 background-color: %3$s;
343 .widget textarea:focus {
348 .dropdown-toggle:focus {
354 wp_add_inline_style( 'twentyfifteen-style', sprintf( $css, $sidebar_link_color, $sidebar_text_color, $sidebar_border_color, $sidebar_border_focus_color ) );
356 add_action( 'wp_enqueue_scripts', 'twentyfifteen_sidebar_text_color_css', 11 );