custom-header.php ➔ bitsy_header_style()   B
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 37
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 18
nc 3
nop 0
dl 0
loc 37
rs 8.8571
c 0
b 0
f 0
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 the_header_image_tag(); ?>
8
 *
9
 * @link https://developer.wordpress.org/themes/functionality/custom-headers/
10
 *
11
 * @package bitsy
12
 */
13
14
/**
15
 * Set up the WordPress core custom header feature.
16
 *
17
 * @uses bitsy_header_style()
18
 */
19
function bitsy_custom_header_setup() {
20
	add_theme_support( 'custom-header', apply_filters( 'bitsy_custom_header_args', array(
21
		'default-image'      => get_template_directory_uri() . 'assets/images/fedora_smoke.jpg',
22
		'header-text'        => true,
23
		'default-text-color' => '000',
24
		'flex-width'         => true,
25
		'width'              => 2000,
26
		'flex-height'        => true,
27
		'height'             => 420,
28
		'wp-head-callback'   => 'bitsy_header_style',
29
	) ) );
30
}
31
32
add_action( 'after_setup_theme', 'bitsy_custom_header_setup' );
33
34
if ( ! function_exists( 'bitsy_header_style' ) ) {
35
	/**
36
	 * Styles the header image and text displayed on the blog.
37
	 *
38
	 * @see bitsy_custom_header_setup().
39
	 */
40
	function bitsy_header_style() {
41
		$header_text_color = get_header_textcolor();
42
43
		/*
44
		 * If no custom options for text are set, let's bail.
45
		 * get_header_textcolor() options: Any hex value, 'blank' to hide text. Default: add_theme_support( 'custom-header' ).
46
		 */
47
		if ( get_theme_support( 'custom-header', 'default-text-color' ) === $header_text_color ) {
48
			return;
49
		}
50
51
		// If we get this far, we have custom styles. Let's do this.
52
		?>
53
        <style type="text/css">
54
            <?php
55
				// Has the text been hidden?
56
				if ( ! display_header_text() ) {
57
			?>
58
            .site-title,
59
            .site-description {
60
                position: absolute;
61
                clip: rect(1px, 1px, 1px, 1px);
62
            }
63
64
            <?php
65
				// If the user has set a custom color for the text use that.
66
				} else {
67
			?>
68
            .site-title a,
69
            .site-description {
70
                color: #<?php echo esc_attr( $header_text_color ); ?>;
71
            }
72
73
            <?php } ?>
74
        </style>
75
		<?php
76
	}
77
}
78