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 ) ) :
138 * No shorthand so the Customizer can override individual properties.
139 * @see https://core.trac.wordpress.org/ticket/31460
141 background-image: url(<?php header_image(); ?>);
142 background-repeat: no-repeat;
143 background-position: 50% 50%;
144 -webkit-background-size: cover;
145 -moz-background-size: cover;
146 -o-background-size: cover;
147 background-size: cover;
150 @media screen and (min-width: 59.6875em) {
154 * No shorthand so the Customizer can override individual properties.
155 * @see https://core.trac.wordpress.org/ticket/31460
157 background-image: url(<?php header_image(); ?>);
158 background-repeat: no-repeat;
159 background-position: 100% 50%;
160 -webkit-background-size: cover;
161 -moz-background-size: cover;
162 -o-background-size: cover;
163 background-size: cover;
168 background: transparent;
174 // Has the text been hidden?
175 if ( ! display_header_text() ) :
179 clip: rect(1px, 1px, 1px, 1px);
186 endif; // twentyfifteen_header_style
189 * Enqueues front-end CSS for the header background color.
191 * @since Twenty Fifteen 1.0
193 * @see wp_add_inline_style()
195 function twentyfifteen_header_background_color_css() {
196 $color_scheme = twentyfifteen_get_color_scheme();
197 $default_color = $color_scheme[1];
198 $header_background_color = get_theme_mod( 'header_background_color', $default_color );
200 // Don't do anything if the current color is the default.
201 if ( $header_background_color === $default_color ) {
206 /* Custom Header Background Color */
209 background-color: %1$s;
212 @media screen and (min-width: 59.6875em) {
215 background-color: transparent;
219 .widget input[type="button"],
220 .widget input[type="reset"],
221 .widget input[type="submit"],
222 .widget_calendar tbody a,
223 .widget_calendar tbody a:hover,
224 .widget_calendar tbody a:focus {
230 wp_add_inline_style( 'twentyfifteen-style', sprintf( $css, $header_background_color ) );
232 add_action( 'wp_enqueue_scripts', 'twentyfifteen_header_background_color_css', 11 );
235 * Enqueues front-end CSS for the sidebar text color.
237 * @since Twenty Fifteen 1.0
239 function twentyfifteen_sidebar_text_color_css() {
240 $color_scheme = twentyfifteen_get_color_scheme();
241 $default_color = $color_scheme[4];
242 $sidebar_link_color = get_theme_mod( 'sidebar_textcolor', $default_color );
244 // Don't do anything if the current color is the default.
245 if ( $sidebar_link_color === $default_color ) {
249 // If we get this far, we have custom styles. Let's do this.
250 $sidebar_link_color_rgb = twentyfifteen_hex2rgb( $sidebar_link_color );
251 $sidebar_text_color = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.7)', $sidebar_link_color_rgb );
252 $sidebar_border_color = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.1)', $sidebar_link_color_rgb );
253 $sidebar_border_focus_color = vsprintf( 'rgba( %1$s, %2$s, %3$s, 0.3)', $sidebar_link_color_rgb );
256 /* Custom Sidebar Text Color */
259 .secondary-toggle:before {
264 .site-title a:focus {
265 color: %1$s; /* Fallback for IE7 and IE8 */
270 border-color: %1$s; /* Fallback for IE7 and IE8 */
274 .secondary-toggle:hover,
275 .secondary-toggle:focus {
276 border-color: %1$s; /* Fallback for IE7 and IE8 */
281 outline-color: %1$s; /* Fallback for IE7 and IE8 */
285 @media screen and (min-width: 59.6875em) {
287 .dropdown-toggle:after,
289 .widget blockquote cite,
290 .widget blockquote small {
295 .widget input[type="button"],
296 .widget input[type="reset"],
297 .widget input[type="submit"],
298 .widget_calendar tbody a {
299 background-color: %1$s;
308 .main-navigation .menu-item-description,
311 .widget .wp-caption-text,
312 .widget .gallery-caption {
316 .widget button:hover,
317 .widget button:focus,
318 .widget input[type="button"]:hover,
319 .widget input[type="button"]:focus,
320 .widget input[type="reset"]:hover,
321 .widget input[type="reset"]:focus,
322 .widget input[type="submit"]:hover,
323 .widget input[type="submit"]:focus,
324 .widget_calendar tbody a:hover,
325 .widget_calendar tbody a:focus {
326 background-color: %2$s;
343 .widget_categories .children,
344 .widget_nav_menu .sub-menu,
345 .widget_pages .children,
346 .widget abbr[title] {
350 .dropdown-toggle:hover,
351 .dropdown-toggle:focus,
353 background-color: %3$s;
357 .widget textarea:focus {
362 .dropdown-toggle:focus {
368 wp_add_inline_style( 'twentyfifteen-style', sprintf( $css, $sidebar_link_color, $sidebar_text_color, $sidebar_border_color, $sidebar_border_focus_color ) );
370 add_action( 'wp_enqueue_scripts', 'twentyfifteen_sidebar_text_color_css', 11 );