]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-content/themes/twentythirteen/inc/custom-header.php
WordPress 3.9.2
[autoinstalls/wordpress.git] / wp-content / themes / twentythirteen / inc / custom-header.php
1 <?php
2 /**
3  * Implement a custom header for Twenty Thirteen
4  *
5  * @link http://codex.wordpress.org/Custom_Headers
6  *
7  * @package WordPress
8  * @subpackage Twenty_Thirteen
9  * @since Twenty Thirteen 1.0
10  */
11
12 /**
13  * Set up the WordPress core custom header arguments and settings.
14  *
15  * @uses add_theme_support() to register support for 3.4 and up.
16  * @uses twentythirteen_header_style() to style front-end.
17  * @uses twentythirteen_admin_header_style() to style wp-admin form.
18  * @uses twentythirteen_admin_header_image() to add custom markup to wp-admin form.
19  * @uses register_default_headers() to set up the bundled header images.
20  *
21  * @since Twenty Thirteen 1.0
22  */
23 function twentythirteen_custom_header_setup() {
24         $args = array(
25                 // Text color and image (empty to use none).
26                 'default-text-color'     => '220e10',
27                 'default-image'          => '%s/images/headers/circle.png',
28
29                 // Set height and width, with a maximum value for the width.
30                 'height'                 => 230,
31                 'width'                  => 1600,
32
33                 // Callbacks for styling the header and the admin preview.
34                 'wp-head-callback'       => 'twentythirteen_header_style',
35                 'admin-head-callback'    => 'twentythirteen_admin_header_style',
36                 'admin-preview-callback' => 'twentythirteen_admin_header_image',
37         );
38
39         add_theme_support( 'custom-header', $args );
40
41         /*
42          * Default custom headers packaged with the theme.
43          * %s is a placeholder for the theme template directory URI.
44          */
45         register_default_headers( array(
46                 'circle' => array(
47                         'url'           => '%s/images/headers/circle.png',
48                         'thumbnail_url' => '%s/images/headers/circle-thumbnail.png',
49                         'description'   => _x( 'Circle', 'header image description', 'twentythirteen' )
50                 ),
51                 'diamond' => array(
52                         'url'           => '%s/images/headers/diamond.png',
53                         'thumbnail_url' => '%s/images/headers/diamond-thumbnail.png',
54                         'description'   => _x( 'Diamond', 'header image description', 'twentythirteen' )
55                 ),
56                 'star' => array(
57                         'url'           => '%s/images/headers/star.png',
58                         'thumbnail_url' => '%s/images/headers/star-thumbnail.png',
59                         'description'   => _x( 'Star', 'header image description', 'twentythirteen' )
60                 ),
61         ) );
62 }
63 add_action( 'after_setup_theme', 'twentythirteen_custom_header_setup', 11 );
64
65 /**
66  * Load our special font CSS files.
67  *
68  * @since Twenty Thirteen 1.0
69  */
70 function twentythirteen_custom_header_fonts() {
71         // Add Source Sans Pro and Bitter fonts.
72         wp_enqueue_style( 'twentythirteen-fonts', twentythirteen_fonts_url(), array(), null );
73
74         // Add Genericons font.
75         wp_enqueue_style( 'genericons', get_template_directory_uri() . '/fonts/genericons.css', array(), '2.09' );
76 }
77 add_action( 'admin_print_styles-appearance_page_custom-header', 'twentythirteen_custom_header_fonts' );
78
79 /**
80  * Style the header text displayed on the blog.
81  *
82  * get_header_textcolor() options: Hide text (returns 'blank'), or any hex value.
83  *
84  * @since Twenty Thirteen 1.0
85  */
86 function twentythirteen_header_style() {
87         $header_image = get_header_image();
88         $text_color   = get_header_textcolor();
89
90         // If no custom options for text are set, let's bail.
91         if ( empty( $header_image ) && $text_color == get_theme_support( 'custom-header', 'default-text-color' ) )
92                 return;
93
94         // If we get this far, we have custom styles.
95         ?>
96         <style type="text/css" id="twentythirteen-header-css">
97         <?php
98                 if ( ! empty( $header_image ) ) :
99         ?>
100                 .site-header {
101                         background: url(<?php header_image(); ?>) no-repeat scroll top;
102                         background-size: 1600px auto;
103                 }
104         <?php
105                 endif;
106
107                 // Has the text been hidden?
108                 if ( ! display_header_text() ) :
109         ?>
110                 .site-title,
111                 .site-description {
112                         position: absolute;
113                         clip: rect(1px 1px 1px 1px); /* IE7 */
114                         clip: rect(1px, 1px, 1px, 1px);
115                 }
116         <?php
117                         if ( empty( $header_image ) ) :
118         ?>
119                 .site-header .home-link {
120                         min-height: 0;
121                 }
122         <?php
123                         endif;
124
125                 // If the user has set a custom color for the text, use that.
126                 elseif ( $text_color != get_theme_support( 'custom-header', 'default-text-color' ) ) :
127         ?>
128                 .site-title,
129                 .site-description {
130                         color: #<?php echo esc_attr( $text_color ); ?>;
131                 }
132         <?php endif; ?>
133         </style>
134         <?php
135 }
136
137 /**
138  * Style the header image displayed on the Appearance > Header admin panel.
139  *
140  * @since Twenty Thirteen 1.0
141  */
142 function twentythirteen_admin_header_style() {
143         $header_image = get_header_image();
144 ?>
145         <style type="text/css" id="twentythirteen-admin-header-css">
146         .appearance_page_custom-header #headimg {
147                 border: none;
148                 -webkit-box-sizing: border-box;
149                 -moz-box-sizing:    border-box;
150                 box-sizing:         border-box;
151                 <?php
152                 if ( ! empty( $header_image ) ) {
153                         echo 'background: url(' . esc_url( $header_image ) . ') no-repeat scroll top; background-size: 1600px auto;';
154                 } ?>
155                 padding: 0 20px;
156         }
157         #headimg .home-link {
158                 -webkit-box-sizing: border-box;
159                 -moz-box-sizing:    border-box;
160                 box-sizing:         border-box;
161                 margin: 0 auto;
162                 max-width: 1040px;
163                 <?php
164                 if ( ! empty( $header_image ) || display_header_text() ) {
165                         echo 'min-height: 230px;';
166                 } ?>
167                 width: 100%;
168         }
169         <?php if ( ! display_header_text() ) : ?>
170         #headimg h1,
171         #headimg h2 {
172                 position: absolute !important;
173                 clip: rect(1px 1px 1px 1px); /* IE7 */
174                 clip: rect(1px, 1px, 1px, 1px);
175         }
176         <?php endif; ?>
177         #headimg h1 {
178                 font: bold 60px/1 Bitter, Georgia, serif;
179                 margin: 0;
180                 padding: 58px 0 10px;
181         }
182         #headimg h1 a {
183                 text-decoration: none;
184         }
185         #headimg h1 a:hover {
186                 text-decoration: underline;
187         }
188         #headimg h2 {
189                 font: 200 italic 24px "Source Sans Pro", Helvetica, sans-serif;
190                 margin: 0;
191                 text-shadow: none;
192         }
193         .default-header img {
194                 max-width: 230px;
195                 width: auto;
196         }
197         </style>
198 <?php
199 }
200
201 /**
202  * Output markup to be displayed on the Appearance > Header admin panel.
203  *
204  * This callback overrides the default markup displayed there.
205  *
206  * @since Twenty Thirteen 1.0
207  */
208 function twentythirteen_admin_header_image() {
209         ?>
210         <div id="headimg" style="background: url(<?php header_image(); ?>) no-repeat scroll top; background-size: 1600px auto;">
211                 <?php $style = ' style="color:#' . get_header_textcolor() . ';"'; ?>
212                 <div class="home-link">
213                         <h1 class="displaying-header-text"><a id="name"<?php echo $style; ?> onclick="return false;" href="#"><?php bloginfo( 'name' ); ?></a></h1>
214                         <h2 id="desc" class="displaying-header-text"<?php echo $style; ?>><?php bloginfo( 'description' ); ?></h2>
215                 </div>
216         </div>
217 <?php }