|
1 <?php |
|
2 /** |
|
3 * Implements an optional custom header for Twenty Twelve. |
|
4 * See http://codex.wordpress.org/Custom_Headers |
|
5 * |
|
6 * @package WordPress |
|
7 * @subpackage Twenty_Twelve |
|
8 * @since Twenty Twelve 1.0 |
|
9 */ |
|
10 |
|
11 /** |
|
12 * Sets up the WordPress core custom header arguments and settings. |
|
13 * |
|
14 * @uses add_theme_support() to register support for 3.4 and up. |
|
15 * @uses twentytwelve_header_style() to style front-end. |
|
16 * @uses twentytwelve_admin_header_style() to style wp-admin form. |
|
17 * @uses twentytwelve_admin_header_image() to add custom markup to wp-admin form. |
|
18 * |
|
19 * @since Twenty Twelve 1.0 |
|
20 */ |
|
21 function twentytwelve_custom_header_setup() { |
|
22 $args = array( |
|
23 // Text color and image (empty to use none). |
|
24 'default-text-color' => '444', |
|
25 'default-image' => '', |
|
26 |
|
27 // Set height and width, with a maximum value for the width. |
|
28 'height' => 250, |
|
29 'width' => 960, |
|
30 'max-width' => 2000, |
|
31 |
|
32 // Support flexible height and width. |
|
33 'flex-height' => true, |
|
34 'flex-width' => true, |
|
35 |
|
36 // Random image rotation off by default. |
|
37 'random-default' => false, |
|
38 |
|
39 // Callbacks for styling the header and the admin preview. |
|
40 'wp-head-callback' => 'twentytwelve_header_style', |
|
41 'admin-head-callback' => 'twentytwelve_admin_header_style', |
|
42 'admin-preview-callback' => 'twentytwelve_admin_header_image', |
|
43 ); |
|
44 |
|
45 add_theme_support( 'custom-header', $args ); |
|
46 } |
|
47 add_action( 'after_setup_theme', 'twentytwelve_custom_header_setup' ); |
|
48 |
|
49 /** |
|
50 * Styles the header text displayed on the blog. |
|
51 * |
|
52 * get_header_textcolor() options: 444 is default, hide text (returns 'blank'), or any hex value. |
|
53 * |
|
54 * @since Twenty Twelve 1.0 |
|
55 */ |
|
56 function twentytwelve_header_style() { |
|
57 $text_color = get_header_textcolor(); |
|
58 |
|
59 // If no custom options for text are set, let's bail |
|
60 if ( $text_color == get_theme_support( 'custom-header', 'default-text-color' ) ) |
|
61 return; |
|
62 |
|
63 // If we get this far, we have custom styles. |
|
64 ?> |
|
65 <style type="text/css"> |
|
66 <?php |
|
67 // Has the text been hidden? |
|
68 if ( ! display_header_text() ) : |
|
69 ?> |
|
70 .site-title, |
|
71 .site-description { |
|
72 position: absolute !important; |
|
73 clip: rect(1px 1px 1px 1px); /* IE7 */ |
|
74 clip: rect(1px, 1px, 1px, 1px); |
|
75 } |
|
76 <?php |
|
77 // If the user has set a custom color for the text, use that. |
|
78 else : |
|
79 ?> |
|
80 .site-title a, |
|
81 .site-description { |
|
82 color: #<?php echo $text_color; ?> !important; |
|
83 } |
|
84 <?php endif; ?> |
|
85 </style> |
|
86 <?php |
|
87 } |
|
88 |
|
89 /** |
|
90 * Styles the header image displayed on the Appearance > Header admin panel. |
|
91 * |
|
92 * @since Twenty Twelve 1.0 |
|
93 */ |
|
94 function twentytwelve_admin_header_style() { |
|
95 ?> |
|
96 <style type="text/css"> |
|
97 .appearance_page_custom-header #headimg { |
|
98 border: none; |
|
99 } |
|
100 #headimg h1, |
|
101 #headimg h2 { |
|
102 line-height: 1.6; |
|
103 margin: 0; |
|
104 padding: 0; |
|
105 } |
|
106 #headimg h1 { |
|
107 font-size: 30px; |
|
108 } |
|
109 #headimg h1 a { |
|
110 color: #515151; |
|
111 text-decoration: none; |
|
112 } |
|
113 #headimg h1 a:hover { |
|
114 color: #21759b; |
|
115 } |
|
116 #headimg h2 { |
|
117 color: #757575; |
|
118 font: normal 13px/1.8 "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", sans-serif; |
|
119 margin-bottom: 24px; |
|
120 } |
|
121 #headimg img { |
|
122 max-width: <?php echo get_theme_support( 'custom-header', 'max-width' ); ?>px; |
|
123 } |
|
124 </style> |
|
125 <?php |
|
126 } |
|
127 |
|
128 /** |
|
129 * Outputs markup to be displayed on the Appearance > Header admin panel. |
|
130 * This callback overrides the default markup displayed there. |
|
131 * |
|
132 * @since Twenty Twelve 1.0 |
|
133 */ |
|
134 function twentytwelve_admin_header_image() { |
|
135 ?> |
|
136 <div id="headimg"> |
|
137 <?php |
|
138 if ( ! display_header_text() ) |
|
139 $style = ' style="display:none;"'; |
|
140 else |
|
141 $style = ' style="color:#' . get_header_textcolor() . ';"'; |
|
142 ?> |
|
143 <h1><a id="name"<?php echo $style; ?> onclick="return false;" href="<?php echo esc_url( home_url( '/' ) ); ?>"><?php bloginfo( 'name' ); ?></a></h1> |
|
144 <h2 id="desc"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></h2> |
|
145 <?php $header_image = get_header_image(); |
|
146 if ( ! empty( $header_image ) ) : ?> |
|
147 <img src="<?php echo esc_url( $header_image ); ?>" class="header-image" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" /> |
|
148 <?php endif; ?> |
|
149 </div> |
|
150 <?php } |