0
|
1 |
<?php |
|
2 |
/** |
|
3 |
* Twenty Twelve functions and definitions |
|
4 |
* |
|
5 |
* Sets up the theme and provides some helper functions, which are used |
|
6 |
* in the theme as custom template tags. Others are attached to action and |
|
7 |
* filter hooks in WordPress to change core functionality. |
|
8 |
* |
5
|
9 |
* When using a child theme (see https://codex.wordpress.org/Theme_Development and |
|
10 |
* https://codex.wordpress.org/Child_Themes), you can override certain functions |
0
|
11 |
* (those wrapped in a function_exists() call) by defining them first in your child theme's |
|
12 |
* functions.php file. The child theme's functions.php file is included before the parent |
|
13 |
* theme's file, so the child theme functions would be used. |
|
14 |
* |
|
15 |
* Functions that are not pluggable (not wrapped in function_exists()) are instead attached |
|
16 |
* to a filter or action hook. |
|
17 |
* |
5
|
18 |
* For more information on hooks, actions, and filters, @link https://codex.wordpress.org/Plugin_API |
0
|
19 |
* |
|
20 |
* @package WordPress |
|
21 |
* @subpackage Twenty_Twelve |
|
22 |
* @since Twenty Twelve 1.0 |
|
23 |
*/ |
|
24 |
|
|
25 |
// Set up the content width value based on the theme's design and stylesheet. |
|
26 |
if ( ! isset( $content_width ) ) |
|
27 |
$content_width = 625; |
|
28 |
|
|
29 |
/** |
|
30 |
* Twenty Twelve setup. |
|
31 |
* |
|
32 |
* Sets up theme defaults and registers the various WordPress features that |
|
33 |
* Twenty Twelve supports. |
|
34 |
* |
|
35 |
* @uses load_theme_textdomain() For translation/localization support. |
|
36 |
* @uses add_editor_style() To add a Visual Editor stylesheet. |
|
37 |
* @uses add_theme_support() To add support for post thumbnails, automatic feed links, |
|
38 |
* custom background, and post formats. |
|
39 |
* @uses register_nav_menu() To add support for navigation menus. |
|
40 |
* @uses set_post_thumbnail_size() To set a custom post thumbnail size. |
|
41 |
* |
|
42 |
* @since Twenty Twelve 1.0 |
|
43 |
*/ |
|
44 |
function twentytwelve_setup() { |
|
45 |
/* |
|
46 |
* Makes Twenty Twelve available for translation. |
|
47 |
* |
|
48 |
* Translations can be added to the /languages/ directory. |
|
49 |
* If you're building a theme based on Twenty Twelve, use a find and replace |
|
50 |
* to change 'twentytwelve' to the name of your theme in all the template files. |
|
51 |
*/ |
|
52 |
load_theme_textdomain( 'twentytwelve', get_template_directory() . '/languages' ); |
|
53 |
|
|
54 |
// This theme styles the visual editor with editor-style.css to match the theme style. |
|
55 |
add_editor_style(); |
|
56 |
|
|
57 |
// Adds RSS feed links to <head> for posts and comments. |
|
58 |
add_theme_support( 'automatic-feed-links' ); |
|
59 |
|
|
60 |
// This theme supports a variety of post formats. |
|
61 |
add_theme_support( 'post-formats', array( 'aside', 'image', 'link', 'quote', 'status' ) ); |
|
62 |
|
|
63 |
// This theme uses wp_nav_menu() in one location. |
|
64 |
register_nav_menu( 'primary', __( 'Primary Menu', 'twentytwelve' ) ); |
|
65 |
|
|
66 |
/* |
|
67 |
* This theme supports custom background color and image, |
|
68 |
* and here we also set up the default background color. |
|
69 |
*/ |
|
70 |
add_theme_support( 'custom-background', array( |
|
71 |
'default-color' => 'e6e6e6', |
|
72 |
) ); |
|
73 |
|
|
74 |
// This theme uses a custom image size for featured images, displayed on "standard" posts. |
|
75 |
add_theme_support( 'post-thumbnails' ); |
|
76 |
set_post_thumbnail_size( 624, 9999 ); // Unlimited height, soft crop |
|
77 |
} |
|
78 |
add_action( 'after_setup_theme', 'twentytwelve_setup' ); |
|
79 |
|
|
80 |
/** |
|
81 |
* Add support for a custom header image. |
|
82 |
*/ |
|
83 |
require( get_template_directory() . '/inc/custom-header.php' ); |
|
84 |
|
|
85 |
/** |
|
86 |
* Return the Google font stylesheet URL if available. |
|
87 |
* |
|
88 |
* The use of Open Sans by default is localized. For languages that use |
|
89 |
* characters not supported by the font, the font can be disabled. |
|
90 |
* |
|
91 |
* @since Twenty Twelve 1.2 |
|
92 |
* |
|
93 |
* @return string Font stylesheet or empty string if disabled. |
|
94 |
*/ |
|
95 |
function twentytwelve_get_font_url() { |
|
96 |
$font_url = ''; |
|
97 |
|
|
98 |
/* translators: If there are characters in your language that are not supported |
|
99 |
* by Open Sans, translate this to 'off'. Do not translate into your own language. |
|
100 |
*/ |
|
101 |
if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'twentytwelve' ) ) { |
|
102 |
$subsets = 'latin,latin-ext'; |
|
103 |
|
|
104 |
/* translators: To add an additional Open Sans character subset specific to your language, |
|
105 |
* translate this to 'greek', 'cyrillic' or 'vietnamese'. Do not translate into your own language. |
|
106 |
*/ |
|
107 |
$subset = _x( 'no-subset', 'Open Sans font: add new subset (greek, cyrillic, vietnamese)', 'twentytwelve' ); |
|
108 |
|
|
109 |
if ( 'cyrillic' == $subset ) |
|
110 |
$subsets .= ',cyrillic,cyrillic-ext'; |
|
111 |
elseif ( 'greek' == $subset ) |
|
112 |
$subsets .= ',greek,greek-ext'; |
|
113 |
elseif ( 'vietnamese' == $subset ) |
|
114 |
$subsets .= ',vietnamese'; |
|
115 |
|
|
116 |
$protocol = is_ssl() ? 'https' : 'http'; |
|
117 |
$query_args = array( |
|
118 |
'family' => 'Open+Sans:400italic,700italic,400,700', |
|
119 |
'subset' => $subsets, |
|
120 |
); |
|
121 |
$font_url = add_query_arg( $query_args, "$protocol://fonts.googleapis.com/css" ); |
|
122 |
} |
|
123 |
|
|
124 |
return $font_url; |
|
125 |
} |
|
126 |
|
|
127 |
/** |
|
128 |
* Enqueue scripts and styles for front-end. |
|
129 |
* |
|
130 |
* @since Twenty Twelve 1.0 |
|
131 |
*/ |
|
132 |
function twentytwelve_scripts_styles() { |
|
133 |
global $wp_styles; |
|
134 |
|
|
135 |
/* |
|
136 |
* Adds JavaScript to pages with the comment form to support |
|
137 |
* sites with threaded comments (when in use). |
|
138 |
*/ |
|
139 |
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) |
|
140 |
wp_enqueue_script( 'comment-reply' ); |
|
141 |
|
|
142 |
// Adds JavaScript for handling the navigation menu hide-and-show behavior. |
5
|
143 |
wp_enqueue_script( 'twentytwelve-navigation', get_template_directory_uri() . '/js/navigation.js', array( 'jquery' ), '20140711', true ); |
0
|
144 |
|
|
145 |
$font_url = twentytwelve_get_font_url(); |
|
146 |
if ( ! empty( $font_url ) ) |
|
147 |
wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), null ); |
|
148 |
|
|
149 |
// Loads our main stylesheet. |
|
150 |
wp_enqueue_style( 'twentytwelve-style', get_stylesheet_uri() ); |
|
151 |
|
|
152 |
// Loads the Internet Explorer specific stylesheet. |
|
153 |
wp_enqueue_style( 'twentytwelve-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentytwelve-style' ), '20121010' ); |
|
154 |
$wp_styles->add_data( 'twentytwelve-ie', 'conditional', 'lt IE 9' ); |
|
155 |
} |
|
156 |
add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' ); |
|
157 |
|
|
158 |
/** |
|
159 |
* Filter TinyMCE CSS path to include Google Fonts. |
|
160 |
* |
|
161 |
* Adds additional stylesheets to the TinyMCE editor if needed. |
|
162 |
* |
|
163 |
* @uses twentytwelve_get_font_url() To get the Google Font stylesheet URL. |
|
164 |
* |
|
165 |
* @since Twenty Twelve 1.2 |
|
166 |
* |
|
167 |
* @param string $mce_css CSS path to load in TinyMCE. |
|
168 |
* @return string Filtered CSS path. |
|
169 |
*/ |
|
170 |
function twentytwelve_mce_css( $mce_css ) { |
|
171 |
$font_url = twentytwelve_get_font_url(); |
|
172 |
|
|
173 |
if ( empty( $font_url ) ) |
|
174 |
return $mce_css; |
|
175 |
|
|
176 |
if ( ! empty( $mce_css ) ) |
|
177 |
$mce_css .= ','; |
|
178 |
|
|
179 |
$mce_css .= esc_url_raw( str_replace( ',', '%2C', $font_url ) ); |
|
180 |
|
|
181 |
return $mce_css; |
|
182 |
} |
|
183 |
add_filter( 'mce_css', 'twentytwelve_mce_css' ); |
|
184 |
|
|
185 |
/** |
|
186 |
* Filter the page title. |
|
187 |
* |
|
188 |
* Creates a nicely formatted and more specific title element text |
|
189 |
* for output in head of document, based on current view. |
|
190 |
* |
|
191 |
* @since Twenty Twelve 1.0 |
|
192 |
* |
|
193 |
* @param string $title Default title text for current view. |
|
194 |
* @param string $sep Optional separator. |
|
195 |
* @return string Filtered title. |
|
196 |
*/ |
|
197 |
function twentytwelve_wp_title( $title, $sep ) { |
|
198 |
global $paged, $page; |
|
199 |
|
|
200 |
if ( is_feed() ) |
|
201 |
return $title; |
|
202 |
|
|
203 |
// Add the site name. |
5
|
204 |
$title .= get_bloginfo( 'name', 'display' ); |
0
|
205 |
|
|
206 |
// Add the site description for the home/front page. |
|
207 |
$site_description = get_bloginfo( 'description', 'display' ); |
|
208 |
if ( $site_description && ( is_home() || is_front_page() ) ) |
|
209 |
$title = "$title $sep $site_description"; |
|
210 |
|
|
211 |
// Add a page number if necessary. |
5
|
212 |
if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) |
0
|
213 |
$title = "$title $sep " . sprintf( __( 'Page %s', 'twentytwelve' ), max( $paged, $page ) ); |
|
214 |
|
|
215 |
return $title; |
|
216 |
} |
|
217 |
add_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 ); |
|
218 |
|
|
219 |
/** |
|
220 |
* Filter the page menu arguments. |
|
221 |
* |
|
222 |
* Makes our wp_nav_menu() fallback -- wp_page_menu() -- show a home link. |
|
223 |
* |
|
224 |
* @since Twenty Twelve 1.0 |
|
225 |
*/ |
|
226 |
function twentytwelve_page_menu_args( $args ) { |
|
227 |
if ( ! isset( $args['show_home'] ) ) |
|
228 |
$args['show_home'] = true; |
|
229 |
return $args; |
|
230 |
} |
|
231 |
add_filter( 'wp_page_menu_args', 'twentytwelve_page_menu_args' ); |
|
232 |
|
|
233 |
/** |
|
234 |
* Register sidebars. |
|
235 |
* |
|
236 |
* Registers our main widget area and the front page widget areas. |
|
237 |
* |
|
238 |
* @since Twenty Twelve 1.0 |
|
239 |
*/ |
|
240 |
function twentytwelve_widgets_init() { |
|
241 |
register_sidebar( array( |
|
242 |
'name' => __( 'Main Sidebar', 'twentytwelve' ), |
|
243 |
'id' => 'sidebar-1', |
|
244 |
'description' => __( 'Appears on posts and pages except the optional Front Page template, which has its own widgets', 'twentytwelve' ), |
|
245 |
'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
|
246 |
'after_widget' => '</aside>', |
|
247 |
'before_title' => '<h3 class="widget-title">', |
|
248 |
'after_title' => '</h3>', |
|
249 |
) ); |
|
250 |
|
|
251 |
register_sidebar( array( |
|
252 |
'name' => __( 'First Front Page Widget Area', 'twentytwelve' ), |
|
253 |
'id' => 'sidebar-2', |
|
254 |
'description' => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ), |
|
255 |
'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
|
256 |
'after_widget' => '</aside>', |
|
257 |
'before_title' => '<h3 class="widget-title">', |
|
258 |
'after_title' => '</h3>', |
|
259 |
) ); |
|
260 |
|
|
261 |
register_sidebar( array( |
|
262 |
'name' => __( 'Second Front Page Widget Area', 'twentytwelve' ), |
|
263 |
'id' => 'sidebar-3', |
|
264 |
'description' => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ), |
|
265 |
'before_widget' => '<aside id="%1$s" class="widget %2$s">', |
|
266 |
'after_widget' => '</aside>', |
|
267 |
'before_title' => '<h3 class="widget-title">', |
|
268 |
'after_title' => '</h3>', |
|
269 |
) ); |
|
270 |
} |
|
271 |
add_action( 'widgets_init', 'twentytwelve_widgets_init' ); |
|
272 |
|
|
273 |
if ( ! function_exists( 'twentytwelve_content_nav' ) ) : |
|
274 |
/** |
|
275 |
* Displays navigation to next/previous pages when applicable. |
|
276 |
* |
|
277 |
* @since Twenty Twelve 1.0 |
|
278 |
*/ |
|
279 |
function twentytwelve_content_nav( $html_id ) { |
|
280 |
global $wp_query; |
|
281 |
|
|
282 |
if ( $wp_query->max_num_pages > 1 ) : ?> |
5
|
283 |
<nav id="<?php echo esc_attr( $html_id ); ?>" class="navigation" role="navigation"> |
0
|
284 |
<h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3> |
|
285 |
<div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentytwelve' ) ); ?></div> |
|
286 |
<div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentytwelve' ) ); ?></div> |
5
|
287 |
</nav><!-- .navigation --> |
0
|
288 |
<?php endif; |
|
289 |
} |
|
290 |
endif; |
|
291 |
|
|
292 |
if ( ! function_exists( 'twentytwelve_comment' ) ) : |
|
293 |
/** |
|
294 |
* Template for comments and pingbacks. |
|
295 |
* |
|
296 |
* To override this walker in a child theme without modifying the comments template |
|
297 |
* simply create your own twentytwelve_comment(), and that function will be used instead. |
|
298 |
* |
|
299 |
* Used as a callback by wp_list_comments() for displaying the comments. |
|
300 |
* |
|
301 |
* @since Twenty Twelve 1.0 |
|
302 |
*/ |
|
303 |
function twentytwelve_comment( $comment, $args, $depth ) { |
|
304 |
$GLOBALS['comment'] = $comment; |
|
305 |
switch ( $comment->comment_type ) : |
|
306 |
case 'pingback' : |
|
307 |
case 'trackback' : |
|
308 |
// Display trackbacks differently than normal comments. |
|
309 |
?> |
|
310 |
<li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>"> |
|
311 |
<p><?php _e( 'Pingback:', 'twentytwelve' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?></p> |
|
312 |
<?php |
|
313 |
break; |
|
314 |
default : |
|
315 |
// Proceed with normal comments. |
|
316 |
global $post; |
|
317 |
?> |
|
318 |
<li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"> |
|
319 |
<article id="comment-<?php comment_ID(); ?>" class="comment"> |
|
320 |
<header class="comment-meta comment-author vcard"> |
|
321 |
<?php |
|
322 |
echo get_avatar( $comment, 44 ); |
|
323 |
printf( '<cite><b class="fn">%1$s</b> %2$s</cite>', |
|
324 |
get_comment_author_link(), |
|
325 |
// If current post author is also comment author, make it known visually. |
|
326 |
( $comment->user_id === $post->post_author ) ? '<span>' . __( 'Post author', 'twentytwelve' ) . '</span>' : '' |
|
327 |
); |
|
328 |
printf( '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>', |
|
329 |
esc_url( get_comment_link( $comment->comment_ID ) ), |
|
330 |
get_comment_time( 'c' ), |
|
331 |
/* translators: 1: date, 2: time */ |
|
332 |
sprintf( __( '%1$s at %2$s', 'twentytwelve' ), get_comment_date(), get_comment_time() ) |
|
333 |
); |
|
334 |
?> |
|
335 |
</header><!-- .comment-meta --> |
|
336 |
|
|
337 |
<?php if ( '0' == $comment->comment_approved ) : ?> |
|
338 |
<p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.', 'twentytwelve' ); ?></p> |
|
339 |
<?php endif; ?> |
|
340 |
|
|
341 |
<section class="comment-content comment"> |
|
342 |
<?php comment_text(); ?> |
|
343 |
<?php edit_comment_link( __( 'Edit', 'twentytwelve' ), '<p class="edit-link">', '</p>' ); ?> |
|
344 |
</section><!-- .comment-content --> |
|
345 |
|
|
346 |
<div class="reply"> |
|
347 |
<?php comment_reply_link( array_merge( $args, array( 'reply_text' => __( 'Reply', 'twentytwelve' ), 'after' => ' <span>↓</span>', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?> |
|
348 |
</div><!-- .reply --> |
|
349 |
</article><!-- #comment-## --> |
|
350 |
<?php |
|
351 |
break; |
|
352 |
endswitch; // end comment_type check |
|
353 |
} |
|
354 |
endif; |
|
355 |
|
|
356 |
if ( ! function_exists( 'twentytwelve_entry_meta' ) ) : |
|
357 |
/** |
|
358 |
* Set up post entry meta. |
|
359 |
* |
|
360 |
* Prints HTML with meta information for current post: categories, tags, permalink, author, and date. |
|
361 |
* |
|
362 |
* Create your own twentytwelve_entry_meta() to override in a child theme. |
|
363 |
* |
|
364 |
* @since Twenty Twelve 1.0 |
|
365 |
*/ |
|
366 |
function twentytwelve_entry_meta() { |
|
367 |
// Translators: used between list items, there is a space after the comma. |
|
368 |
$categories_list = get_the_category_list( __( ', ', 'twentytwelve' ) ); |
|
369 |
|
|
370 |
// Translators: used between list items, there is a space after the comma. |
|
371 |
$tag_list = get_the_tag_list( '', __( ', ', 'twentytwelve' ) ); |
|
372 |
|
|
373 |
$date = sprintf( '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>', |
|
374 |
esc_url( get_permalink() ), |
|
375 |
esc_attr( get_the_time() ), |
|
376 |
esc_attr( get_the_date( 'c' ) ), |
|
377 |
esc_html( get_the_date() ) |
|
378 |
); |
|
379 |
|
|
380 |
$author = sprintf( '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>', |
|
381 |
esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), |
|
382 |
esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ), |
|
383 |
get_the_author() |
|
384 |
); |
|
385 |
|
|
386 |
// Translators: 1 is category, 2 is tag, 3 is the date and 4 is the author's name. |
|
387 |
if ( $tag_list ) { |
|
388 |
$utility_text = __( 'This entry was posted in %1$s and tagged %2$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' ); |
|
389 |
} elseif ( $categories_list ) { |
|
390 |
$utility_text = __( 'This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' ); |
|
391 |
} else { |
|
392 |
$utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' ); |
|
393 |
} |
|
394 |
|
|
395 |
printf( |
|
396 |
$utility_text, |
|
397 |
$categories_list, |
|
398 |
$tag_list, |
|
399 |
$date, |
|
400 |
$author |
|
401 |
); |
|
402 |
} |
|
403 |
endif; |
|
404 |
|
|
405 |
/** |
|
406 |
* Extend the default WordPress body classes. |
|
407 |
* |
|
408 |
* Extends the default WordPress body class to denote: |
|
409 |
* 1. Using a full-width layout, when no active widgets in the sidebar |
|
410 |
* or full-width template. |
|
411 |
* 2. Front Page template: thumbnail in use and number of sidebars for |
|
412 |
* widget areas. |
|
413 |
* 3. White or empty background color to change the layout and spacing. |
|
414 |
* 4. Custom fonts enabled. |
|
415 |
* 5. Single or multiple authors. |
|
416 |
* |
|
417 |
* @since Twenty Twelve 1.0 |
|
418 |
* |
|
419 |
* @param array $classes Existing class values. |
|
420 |
* @return array Filtered class values. |
|
421 |
*/ |
|
422 |
function twentytwelve_body_class( $classes ) { |
|
423 |
$background_color = get_background_color(); |
|
424 |
$background_image = get_background_image(); |
|
425 |
|
|
426 |
if ( ! is_active_sidebar( 'sidebar-1' ) || is_page_template( 'page-templates/full-width.php' ) ) |
|
427 |
$classes[] = 'full-width'; |
|
428 |
|
|
429 |
if ( is_page_template( 'page-templates/front-page.php' ) ) { |
|
430 |
$classes[] = 'template-front-page'; |
|
431 |
if ( has_post_thumbnail() ) |
|
432 |
$classes[] = 'has-post-thumbnail'; |
|
433 |
if ( is_active_sidebar( 'sidebar-2' ) && is_active_sidebar( 'sidebar-3' ) ) |
|
434 |
$classes[] = 'two-sidebars'; |
|
435 |
} |
|
436 |
|
|
437 |
if ( empty( $background_image ) ) { |
|
438 |
if ( empty( $background_color ) ) |
|
439 |
$classes[] = 'custom-background-empty'; |
|
440 |
elseif ( in_array( $background_color, array( 'fff', 'ffffff' ) ) ) |
|
441 |
$classes[] = 'custom-background-white'; |
|
442 |
} |
|
443 |
|
|
444 |
// Enable custom font class only if the font CSS is queued to load. |
|
445 |
if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) ) |
|
446 |
$classes[] = 'custom-font-enabled'; |
|
447 |
|
|
448 |
if ( ! is_multi_author() ) |
|
449 |
$classes[] = 'single-author'; |
|
450 |
|
|
451 |
return $classes; |
|
452 |
} |
|
453 |
add_filter( 'body_class', 'twentytwelve_body_class' ); |
|
454 |
|
|
455 |
/** |
|
456 |
* Adjust content width in certain contexts. |
|
457 |
* |
|
458 |
* Adjusts content_width value for full-width and single image attachment |
|
459 |
* templates, and when there are no active widgets in the sidebar. |
|
460 |
* |
|
461 |
* @since Twenty Twelve 1.0 |
|
462 |
*/ |
|
463 |
function twentytwelve_content_width() { |
|
464 |
if ( is_page_template( 'page-templates/full-width.php' ) || is_attachment() || ! is_active_sidebar( 'sidebar-1' ) ) { |
|
465 |
global $content_width; |
|
466 |
$content_width = 960; |
|
467 |
} |
|
468 |
} |
|
469 |
add_action( 'template_redirect', 'twentytwelve_content_width' ); |
|
470 |
|
|
471 |
/** |
|
472 |
* Register postMessage support. |
|
473 |
* |
|
474 |
* Add postMessage support for site title and description for the Customizer. |
|
475 |
* |
|
476 |
* @since Twenty Twelve 1.0 |
|
477 |
* |
|
478 |
* @param WP_Customize_Manager $wp_customize Customizer object. |
|
479 |
*/ |
|
480 |
function twentytwelve_customize_register( $wp_customize ) { |
|
481 |
$wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; |
|
482 |
$wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; |
|
483 |
$wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; |
|
484 |
} |
|
485 |
add_action( 'customize_register', 'twentytwelve_customize_register' ); |
|
486 |
|
|
487 |
/** |
|
488 |
* Enqueue Javascript postMessage handlers for the Customizer. |
|
489 |
* |
|
490 |
* Binds JS handlers to make the Customizer preview reload changes asynchronously. |
|
491 |
* |
|
492 |
* @since Twenty Twelve 1.0 |
|
493 |
*/ |
|
494 |
function twentytwelve_customize_preview_js() { |
5
|
495 |
wp_enqueue_script( 'twentytwelve-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20141120', true ); |
0
|
496 |
} |
|
497 |
add_action( 'customize_preview_init', 'twentytwelve_customize_preview_js' ); |