| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
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 * 9 * When using a child theme you can override certain functions (those wrapped 10 * in a function_exists() call) by defining them first in your child theme's 11 * functions.php file. The child theme's functions.php file is included before 12 * the parent theme's file, so the child theme functions would be used. 13 * 14 * @link https://developer.wordpress.org/themes/basics/theme-functions/ 15 * @link https://developer.wordpress.org/themes/advanced-topics/child-themes/ 16 * 17 * Functions that are not pluggable (not wrapped in function_exists()) are instead attached 18 * to a filter or action hook. 19 * 20 * For more information on hooks, actions, and filters, @link https://developer.wordpress.org/plugins/ 21 * 22 * @package WordPress 23 * @subpackage Twenty_Twelve 24 * @since Twenty Twelve 1.0 25 */ 26 27 // Set up the content width value based on the theme's design and stylesheet. 28 if ( ! isset( $content_width ) ) { 29 $content_width = 625; 30 } 31 32 /** 33 * Twenty Twelve setup. 34 * 35 * Sets up theme defaults and registers the various WordPress features that 36 * Twenty Twelve supports. 37 * 38 * @uses load_theme_textdomain() For translation/localization support. 39 * @uses add_editor_style() To add a Visual Editor stylesheet. 40 * @uses add_theme_support() To add support for post thumbnails, automatic feed links, 41 * custom background, and post formats. 42 * @uses register_nav_menu() To add support for navigation menus. 43 * @uses set_post_thumbnail_size() To set a custom post thumbnail size. 44 * 45 * @since Twenty Twelve 1.0 46 * 47 * @global string $wp_version The WordPress version string. 48 */ 49 function twentytwelve_setup() { 50 /* 51 * Makes Twenty Twelve available for translation. 52 * 53 * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentytwelve 54 * If you're building a theme based on Twenty Twelve, use a find and replace 55 * to change 'twentytwelve' to the name of your theme in all the template files. 56 * 57 * Manual loading of text domain is not required after the introduction of 58 * just in time translation loading in WordPress version 4.6. 59 * 60 * @ticket 58318 61 */ 62 if ( version_compare( $GLOBALS['wp_version'], '4.6', '<' ) ) { 63 load_theme_textdomain( 'twentytwelve' ); 64 } 65 66 // This theme styles the visual editor with editor-style.css to match the theme style. 67 add_editor_style(); 68 69 // Load regular editor styles into the new block-based editor. 70 add_theme_support( 'editor-styles' ); 71 72 // Load default block styles. 73 add_theme_support( 'wp-block-styles' ); 74 75 // Add support for responsive embeds. 76 add_theme_support( 'responsive-embeds' ); 77 78 // Add support for custom color scheme. 79 add_theme_support( 80 'editor-color-palette', 81 array( 82 array( 83 'name' => __( 'Blue', 'twentytwelve' ), 84 'slug' => 'blue', 85 'color' => '#21759b', 86 ), 87 array( 88 'name' => __( 'Dark Gray', 'twentytwelve' ), 89 'slug' => 'dark-gray', 90 'color' => '#444', 91 ), 92 array( 93 'name' => __( 'Medium Gray', 'twentytwelve' ), 94 'slug' => 'medium-gray', 95 'color' => '#9f9f9f', 96 ), 97 array( 98 'name' => __( 'Light Gray', 'twentytwelve' ), 99 'slug' => 'light-gray', 100 'color' => '#e6e6e6', 101 ), 102 array( 103 'name' => __( 'White', 'twentytwelve' ), 104 'slug' => 'white', 105 'color' => '#fff', 106 ), 107 ) 108 ); 109 110 // Adds RSS feed links to <head> for posts and comments. 111 add_theme_support( 'automatic-feed-links' ); 112 113 // This theme supports a variety of post formats. 114 add_theme_support( 'post-formats', array( 'aside', 'image', 'link', 'quote', 'status' ) ); 115 116 // This theme uses wp_nav_menu() in one location. 117 register_nav_menu( 'primary', __( 'Primary Menu', 'twentytwelve' ) ); 118 119 /* 120 * This theme supports custom background color and image, 121 * and here we also set up the default background color. 122 */ 123 add_theme_support( 124 'custom-background', 125 array( 126 'default-color' => 'e6e6e6', 127 ) 128 ); 129 130 // This theme uses a custom image size for featured images, displayed on "standard" posts. 131 add_theme_support( 'post-thumbnails' ); 132 set_post_thumbnail_size( 624, 9999 ); // Unlimited height, soft crop. 133 134 // Indicate widget sidebars can use selective refresh in the Customizer. 135 add_theme_support( 'customize-selective-refresh-widgets' ); 136 } 137 add_action( 'after_setup_theme', 'twentytwelve_setup' ); 138 139 /** 140 * Adds support for a custom header image. 141 */ 142 require get_template_directory() . '/inc/custom-header.php'; 143 144 /** 145 * Registers block patterns and pattern categories. 146 * 147 * @since Twenty Twelve 4.4 148 */ 149 function twentytwelve_register_block_patterns() { 150 require get_template_directory() . '/inc/block-patterns.php'; 151 } 152 153 add_action( 'init', 'twentytwelve_register_block_patterns' ); 154 155 if ( ! function_exists( 'twentytwelve_get_font_url' ) ) : 156 /** 157 * Return the font stylesheet URL if available. 158 * 159 * The use of Open Sans by default is localized. For languages that use 160 * characters not supported by the font, the font can be disabled. 161 * 162 * @since Twenty Twelve 1.2 163 * @since Twenty Twelve 3.9 Replaced Google URL with self-hosted font. 164 * 165 * @return string Font stylesheet URL or empty string if disabled. 166 */ 167 function twentytwelve_get_font_url() { 168 $font_url = ''; 169 170 /* 171 * translators: If there are characters in your language that are not supported 172 * by Open Sans, translate this to 'off'. Do not translate into your own language. 173 */ 174 if ( 'off' !== _x( 'on', 'Open Sans font: on or off', 'twentytwelve' ) ) { 175 $font_url = get_template_directory_uri() . '/fonts/font-open-sans.css'; 176 } 177 178 return $font_url; 179 } 180 endif; 181 182 /** 183 * Enqueues scripts and styles for front end. 184 * 185 * @since Twenty Twelve 1.0 186 * 187 * @global WP_Styles $wp_styles The WP_Styles object for printing styles. 188 */ 189 function twentytwelve_scripts_styles() { 190 global $wp_styles; 191 192 /* 193 * Adds JavaScript to pages with the comment form to support 194 * sites with threaded comments (when in use). 195 */ 196 if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { 197 wp_enqueue_script( 'comment-reply' ); 198 } 199 200 // Adds JavaScript for handling the navigation menu hide-and-show behavior. 201 wp_enqueue_script( 202 'twentytwelve-navigation', 203 get_template_directory_uri() . '/js/navigation.js', 204 array( 'jquery' ), 205 '20250303', 206 array( 207 'in_footer' => false, // Because involves header. 208 'strategy' => 'defer', 209 ) 210 ); 211 212 $font_url = twentytwelve_get_font_url(); 213 if ( ! empty( $font_url ) ) { 214 $font_version = ( 0 === strpos( (string) twentytwelve_get_font_url(), get_template_directory_uri() . '/' ) ) ? '20230328' : null; 215 wp_enqueue_style( 'twentytwelve-fonts', esc_url_raw( $font_url ), array(), $font_version ); 216 } 217 218 // Loads our main stylesheet. 219 wp_enqueue_style( 'twentytwelve-style', get_stylesheet_uri(), array(), '20260819' ); 220 221 // Theme block stylesheet. 222 wp_enqueue_style( 'twentytwelve-block-style', get_template_directory_uri() . '/css/blocks.css', array( 'twentytwelve-style' ), '20251031' ); 223 224 // Register the Internet Explorer specific stylesheet. 225 wp_register_style( 'twentytwelve-ie', false, array( 'twentytwelve-style' ) ); 226 } 227 add_action( 'wp_enqueue_scripts', 'twentytwelve_scripts_styles' ); 228 229 /** 230 * Enqueues styles for the block-based editor. 231 * 232 * @since Twenty Twelve 2.6 233 */ 234 function twentytwelve_block_editor_styles() { 235 // Block styles. 236 wp_enqueue_style( 'twentytwelve-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css', array(), '20260324' ); 237 // Add custom fonts. 238 $font_version = ( 0 === strpos( (string) twentytwelve_get_font_url(), get_template_directory_uri() . '/' ) ) ? '20230328' : null; 239 wp_enqueue_style( 'twentytwelve-fonts', twentytwelve_get_font_url(), array(), $font_version ); 240 } 241 add_action( 'enqueue_block_editor_assets', 'twentytwelve_block_editor_styles' ); 242 243 /** 244 * Adds preconnect for Google Fonts. 245 * 246 * @since Twenty Twelve 2.2 247 * @deprecated Twenty Twelve 3.9 Disabled filter because, by default, fonts are self-hosted. 248 * 249 * @global string $wp_version The WordPress version string. 250 * 251 * @param array $urls URLs to print for resource hints. 252 * @param string $relation_type The relation type the URLs are printed. 253 * @return array URLs to print for resource hints. 254 */ 255 function twentytwelve_resource_hints( $urls, $relation_type ) { 256 if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) && 'preconnect' === $relation_type ) { 257 if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) { 258 $urls[] = array( 259 'href' => 'https://fonts.gstatic.com', 260 'crossorigin', 261 ); 262 } else { 263 $urls[] = 'https://fonts.gstatic.com'; 264 } 265 } 266 267 return $urls; 268 } 269 // add_filter( 'wp_resource_hints', 'twentytwelve_resource_hints', 10, 2 ); 270 271 /** 272 * Filters TinyMCE CSS path to include hosted fonts. 273 * 274 * Adds additional stylesheets to the TinyMCE editor if needed. 275 * 276 * @uses twentytwelve_get_font_url() To get the font stylesheet URL. 277 * 278 * @since Twenty Twelve 1.2 279 * 280 * @param string $mce_css CSS path to load in TinyMCE. 281 * @return string Filtered CSS path. 282 */ 283 function twentytwelve_mce_css( $mce_css ) { 284 $font_url = twentytwelve_get_font_url(); 285 286 if ( empty( $font_url ) ) { 287 return $mce_css; 288 } 289 290 if ( ! empty( $mce_css ) ) { 291 $mce_css .= ','; 292 } 293 294 $mce_css .= esc_url_raw( str_replace( ',', '%2C', $font_url ) ); 295 296 return $mce_css; 297 } 298 add_filter( 'mce_css', 'twentytwelve_mce_css' ); 299 300 /** 301 * Filters the page title. 302 * 303 * Creates a nicely formatted and more specific title element text 304 * for output in head of document, based on current view. 305 * 306 * @since Twenty Twelve 1.0 307 * 308 * @global int $paged Page number of a list of posts. 309 * @global int $page Page number of a single post. 310 * 311 * @param string $title Default title text for current view. 312 * @param string $sep Optional separator. 313 * @return string Filtered title. 314 */ 315 function twentytwelve_wp_title( $title, $sep ) { 316 global $paged, $page; 317 318 if ( is_feed() ) { 319 return $title; 320 } 321 322 // Add the site name. 323 $title .= get_bloginfo( 'name', 'display' ); 324 325 // Add the site description for the home/front page. 326 $site_description = get_bloginfo( 'description', 'display' ); 327 if ( $site_description && ( is_home() || is_front_page() ) ) { 328 $title = "$title $sep $site_description"; 329 } 330 331 // Add a page number if necessary. 332 if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) { 333 /* translators: %s: Page number. */ 334 $title = "$title $sep " . sprintf( __( 'Page %s', 'twentytwelve' ), max( $paged, $page ) ); 335 } 336 337 return $title; 338 } 339 add_filter( 'wp_title', 'twentytwelve_wp_title', 10, 2 ); 340 341 /** 342 * Filters the page menu arguments. 343 * 344 * Makes our wp_nav_menu() fallback -- wp_page_menu() -- show a home link. 345 * 346 * @since Twenty Twelve 1.0 347 * 348 * @param array $args An array of page menu arguments. See wp_page_menu() for information 349 * on accepted arguments. 350 * @return array Filtered page menu arguments. 351 */ 352 function twentytwelve_page_menu_args( $args ) { 353 if ( ! isset( $args['show_home'] ) ) { 354 $args['show_home'] = true; 355 } 356 return $args; 357 } 358 add_filter( 'wp_page_menu_args', 'twentytwelve_page_menu_args' ); 359 360 /** 361 * Registers sidebars. 362 * 363 * Registers our main widget area and the front page widget areas. 364 * 365 * @since Twenty Twelve 1.0 366 */ 367 function twentytwelve_widgets_init() { 368 register_sidebar( 369 array( 370 'name' => __( 'Main Sidebar', 'twentytwelve' ), 371 'id' => 'sidebar-1', 372 'description' => __( 'Appears on posts and pages except the optional Front Page template, which has its own widgets', 'twentytwelve' ), 373 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 374 'after_widget' => '</aside>', 375 'before_title' => '<h3 class="widget-title">', 376 'after_title' => '</h3>', 377 ) 378 ); 379 380 register_sidebar( 381 array( 382 'name' => __( 'First Front Page Widget Area', 'twentytwelve' ), 383 'id' => 'sidebar-2', 384 'description' => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ), 385 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 386 'after_widget' => '</aside>', 387 'before_title' => '<h3 class="widget-title">', 388 'after_title' => '</h3>', 389 ) 390 ); 391 392 register_sidebar( 393 array( 394 'name' => __( 'Second Front Page Widget Area', 'twentytwelve' ), 395 'id' => 'sidebar-3', 396 'description' => __( 'Appears when using the optional Front Page template with a page set as Static Front Page', 'twentytwelve' ), 397 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 398 'after_widget' => '</aside>', 399 'before_title' => '<h3 class="widget-title">', 400 'after_title' => '</h3>', 401 ) 402 ); 403 } 404 add_action( 'widgets_init', 'twentytwelve_widgets_init' ); 405 406 if ( ! function_exists( 'wp_get_list_item_separator' ) ) : 407 /** 408 * Retrieves the list item separator based on the locale. 409 * 410 * Added for backward compatibility to support pre-6.0.0 WordPress versions. 411 * 412 * @since Twenty Twelve 3.7 413 * 414 * @return string Locale-specific list item separator. 415 */ 416 function wp_get_list_item_separator() { 417 /* translators: Used between list items, there is a space after the comma. */ 418 return __( ', ', 'twentytwelve' ); 419 } 420 endif; 421 422 if ( ! function_exists( 'twentytwelve_content_nav' ) ) : 423 /** 424 * Displays navigation to next/previous pages when applicable. 425 * 426 * @since Twenty Twelve 1.0 427 * 428 * @global WP_Query $wp_query WordPress Query object. 429 * 430 * @param string $html_id The HTML id attribute for the navigation element. 431 */ 432 function twentytwelve_content_nav( $html_id ) { 433 global $wp_query; 434 435 if ( $wp_query->max_num_pages > 1 ) : 436 $order = get_query_var( 'order', 'DESC' ); 437 $is_desc = ( 'DESC' === $order ); 438 439 $new_posts_text = __( 'Newer posts <span class="meta-nav">→</span>', 'twentytwelve' ); 440 $old_posts_text = __( '<span class="meta-nav">←</span> Older posts', 'twentytwelve' ); 441 442 $prev_link = $is_desc ? get_next_posts_link( $old_posts_text ) : get_previous_posts_link( $old_posts_text ); 443 $next_link = $is_desc ? get_previous_posts_link( $new_posts_text ) : get_next_posts_link( $new_posts_text ); 444 ?> 445 <nav id="<?php echo esc_attr( $html_id ); ?>" class="navigation"> 446 <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentytwelve' ); ?></h3> 447 <?php if ( $prev_link ) : ?> 448 <div class="nav-previous"><?php echo $prev_link; ?></div> 449 <?php endif; ?> 450 451 <?php if ( $next_link ) : ?> 452 <div class="nav-next"><?php echo $next_link; ?></div> 453 <?php endif; ?> 454 </nav><!-- .navigation --> 455 <?php 456 endif; 457 } 458 endif; 459 460 if ( ! function_exists( 'twentytwelve_comment' ) ) : 461 /** 462 * Template for comments and pingbacks. 463 * 464 * To override this walker in a child theme without modifying the comments template 465 * simply create your own twentytwelve_comment(), and that function will be used instead. 466 * 467 * Used as a callback by wp_list_comments() for displaying the comments. 468 * 469 * @since Twenty Twelve 1.0 470 * 471 * @global WP_Comment $comment Global comment object. 472 * @global WP_Post $post Global post object. 473 * 474 * @param WP_Comment $comment The comment object. 475 * @param array $args An array of comment arguments. @see get_comment_reply_link() 476 * @param int $depth The depth of the comment. 477 */ 478 function twentytwelve_comment( $comment, $args, $depth ) { 479 $GLOBALS['comment'] = $comment; 480 switch ( $comment->comment_type ) : 481 case 'pingback': 482 case 'trackback': 483 // Display trackbacks differently than normal comments. 484 ?> 485 <li <?php comment_class(); ?> id="comment-<?php comment_ID(); ?>"> 486 <p><?php _e( 'Pingback:', 'twentytwelve' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( '(Edit)', 'twentytwelve' ), '<span class="edit-link">', '</span>' ); ?></p> 487 <?php 488 break; 489 default: 490 // Proceed with normal comments. 491 global $post; 492 ?> 493 <li <?php comment_class(); ?> id="li-comment-<?php comment_ID(); ?>"> 494 <article id="comment-<?php comment_ID(); ?>" class="comment"> 495 <header class="comment-meta comment-author vcard"> 496 <?php 497 echo get_avatar( $comment, 44 ); 498 printf( 499 '<cite><b class="fn">%1$s</b> %2$s</cite>', 500 get_comment_author_link(), 501 // If current post author is also comment author, make it known visually. 502 ( $comment->user_id === $post->post_author ) ? '<span>' . __( 'Post author', 'twentytwelve' ) . '</span>' : '' 503 ); 504 printf( 505 '<a href="%1$s"><time datetime="%2$s">%3$s</time></a>', 506 esc_url( get_comment_link( $comment->comment_ID ) ), 507 get_comment_time( 'c' ), 508 /* translators: 1: Date, 2: Time. */ 509 sprintf( __( '%1$s at %2$s', 'twentytwelve' ), get_comment_date(), get_comment_time() ) 510 ); 511 ?> 512 </header><!-- .comment-meta --> 513 514 <?php 515 $commenter = wp_get_current_commenter(); 516 if ( $commenter['comment_author_email'] ) { 517 $moderation_note = __( 'Your comment is awaiting moderation.', 'twentytwelve' ); 518 } else { 519 $moderation_note = __( 'Your comment is awaiting moderation. This is a preview; your comment will be visible after it has been approved.', 'twentytwelve' ); 520 } 521 ?> 522 523 <?php if ( '0' === $comment->comment_approved ) : ?> 524 <p class="comment-awaiting-moderation"><?php echo $moderation_note; ?></p> 525 <?php endif; ?> 526 527 <section class="comment-content comment"> 528 <?php comment_text(); ?> 529 <?php edit_comment_link( __( 'Edit', 'twentytwelve' ), '<p class="edit-link">', '</p>' ); ?> 530 </section><!-- .comment-content --> 531 532 <div class="reply"> 533 <?php 534 comment_reply_link( 535 array_merge( 536 $args, 537 array( 538 'reply_text' => __( 'Reply', 'twentytwelve' ), 539 'after' => ' <span>↓</span>', 540 'depth' => $depth, 541 'max_depth' => $args['max_depth'], 542 ) 543 ) 544 ); 545 ?> 546 </div><!-- .reply --> 547 </article><!-- #comment-## --> 548 <?php 549 break; 550 endswitch; // End comment_type check. 551 } 552 endif; 553 554 if ( ! function_exists( 'twentytwelve_entry_meta' ) ) : 555 /** 556 * Sets up post entry meta. 557 * 558 * Prints HTML with meta information for current post: categories, tags, permalink, author, and date. 559 * 560 * Create your own twentytwelve_entry_meta() to override in a child theme. 561 * 562 * @since Twenty Twelve 1.0 563 */ 564 function twentytwelve_entry_meta() { 565 $categories_list = get_the_category_list( wp_get_list_item_separator() ); 566 567 $tags_list = get_the_tag_list( '', wp_get_list_item_separator() ); 568 569 $date = sprintf( 570 '<a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a>', 571 esc_url( get_permalink() ), 572 esc_attr( get_the_time() ), 573 esc_attr( get_the_date( 'c' ) ), 574 esc_html( get_the_date() ) 575 ); 576 577 $author = sprintf( 578 '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>', 579 esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), 580 /* translators: %s: Author display name. */ 581 esc_attr( sprintf( __( 'View all posts by %s', 'twentytwelve' ), get_the_author() ) ), 582 get_the_author() 583 ); 584 585 if ( $tags_list && ! is_wp_error( $tags_list ) ) { 586 /* translators: 1: Category name, 2: Tag name, 3: Date, 4: Author display name. */ 587 $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' ); 588 } elseif ( $categories_list ) { 589 /* translators: 1: Category name, 3: Date, 4: Author display name. */ 590 $utility_text = __( 'This entry was posted in %1$s on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' ); 591 } else { 592 /* translators: 3: Date, 4: Author display name. */ 593 $utility_text = __( 'This entry was posted on %3$s<span class="by-author"> by %4$s</span>.', 'twentytwelve' ); 594 } 595 596 printf( 597 $utility_text, 598 $categories_list, 599 $tags_list, 600 $date, 601 $author 602 ); 603 } 604 endif; 605 606 /** 607 * Extends the default WordPress body classes. 608 * 609 * Extends the default WordPress body class to denote: 610 * 1. Using a full-width layout, when no active widgets in the sidebar 611 * or full-width template. 612 * 2. Front Page template: thumbnail in use and number of sidebars for 613 * widget areas. 614 * 3. White or empty background color to change the layout and spacing. 615 * 4. Custom fonts enabled. 616 * 5. Single or multiple authors. 617 * 618 * @since Twenty Twelve 1.0 619 * 620 * @param array $classes Existing class values. 621 * @return array Filtered class values. 622 */ 623 function twentytwelve_body_class( $classes ) { 624 $background_color = get_background_color(); 625 $background_image = get_background_image(); 626 627 if ( ! is_active_sidebar( 'sidebar-1' ) || is_page_template( 'page-templates/full-width.php' ) ) { 628 $classes[] = 'full-width'; 629 } 630 631 if ( is_page_template( 'page-templates/front-page.php' ) ) { 632 $classes[] = 'template-front-page'; 633 if ( has_post_thumbnail() ) { 634 $classes[] = 'has-post-thumbnail'; 635 } 636 if ( is_active_sidebar( 'sidebar-2' ) && is_active_sidebar( 'sidebar-3' ) ) { 637 $classes[] = 'two-sidebars'; 638 } 639 } 640 641 if ( empty( $background_image ) ) { 642 if ( empty( $background_color ) ) { 643 $classes[] = 'custom-background-empty'; 644 } elseif ( in_array( $background_color, array( 'fff', 'ffffff' ), true ) ) { 645 $classes[] = 'custom-background-white'; 646 } 647 } 648 649 // Enable custom font class only if the font CSS is queued to load. 650 if ( wp_style_is( 'twentytwelve-fonts', 'queue' ) ) { 651 $classes[] = 'custom-font-enabled'; 652 } 653 654 if ( ! is_multi_author() ) { 655 $classes[] = 'single-author'; 656 } 657 658 return $classes; 659 } 660 add_filter( 'body_class', 'twentytwelve_body_class' ); 661 662 /** 663 * Adjusts content width in certain contexts. 664 * 665 * Adjusts content_width value for full-width and single image attachment 666 * templates, and when there are no active widgets in the sidebar. 667 * 668 * @since Twenty Twelve 1.0 669 * 670 * @global int $content_width Content width. 671 */ 672 function twentytwelve_content_width() { 673 if ( is_page_template( 'page-templates/full-width.php' ) || is_attachment() || ! is_active_sidebar( 'sidebar-1' ) ) { 674 global $content_width; 675 $content_width = 960; 676 } 677 } 678 add_action( 'template_redirect', 'twentytwelve_content_width' ); 679 680 /** 681 * Registers postMessage support. 682 * 683 * Adds postMessage support for site title and description for the Customizer. 684 * 685 * @since Twenty Twelve 1.0 686 * 687 * @param WP_Customize_Manager $wp_customize Customizer object. 688 */ 689 function twentytwelve_customize_register( $wp_customize ) { 690 $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; 691 $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; 692 $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; 693 694 if ( isset( $wp_customize->selective_refresh ) ) { 695 $wp_customize->selective_refresh->add_partial( 696 'blogname', 697 array( 698 'selector' => '.site-title > a', 699 'container_inclusive' => false, 700 'render_callback' => 'twentytwelve_customize_partial_blogname', 701 ) 702 ); 703 $wp_customize->selective_refresh->add_partial( 704 'blogdescription', 705 array( 706 'selector' => '.site-description', 707 'container_inclusive' => false, 708 'render_callback' => 'twentytwelve_customize_partial_blogdescription', 709 ) 710 ); 711 } 712 } 713 add_action( 'customize_register', 'twentytwelve_customize_register' ); 714 715 /** 716 * Renders the site title for the selective refresh partial. 717 * 718 * @since Twenty Twelve 2.0 719 * 720 * @see twentytwelve_customize_register() 721 * 722 * @return void 723 */ 724 function twentytwelve_customize_partial_blogname() { 725 bloginfo( 'name' ); 726 } 727 728 /** 729 * Renders the site tagline for the selective refresh partial. 730 * 731 * @since Twenty Twelve 2.0 732 * 733 * @see twentytwelve_customize_register() 734 * 735 * @return void 736 */ 737 function twentytwelve_customize_partial_blogdescription() { 738 bloginfo( 'description' ); 739 } 740 741 /** 742 * Enqueues JavaScript postMessage handlers for the Customizer. 743 * 744 * Binds JS handlers to make the Customizer preview reload changes asynchronously. 745 * 746 * @since Twenty Twelve 1.0 747 */ 748 function twentytwelve_customize_preview_js() { 749 wp_enqueue_script( 'twentytwelve-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20250217', array( 'in_footer' => true ) ); 750 } 751 add_action( 'customize_preview_init', 'twentytwelve_customize_preview_js' ); 752 753 /** 754 * Modifies tag cloud widget arguments to display all tags in the same font size 755 * and use list format for better accessibility. 756 * 757 * @since Twenty Twelve 2.4 758 * 759 * @param array $args Arguments for tag cloud widget. 760 * @return array The filtered arguments for tag cloud widget. 761 */ 762 function twentytwelve_widget_tag_cloud_args( $args ) { 763 $args['largest'] = 22; 764 $args['smallest'] = 8; 765 $args['unit'] = 'pt'; 766 $args['format'] = 'list'; 767 768 return $args; 769 } 770 add_filter( 'widget_tag_cloud_args', 'twentytwelve_widget_tag_cloud_args' ); 771 772 if ( ! function_exists( 'wp_body_open' ) ) : 773 /** 774 * Fires the wp_body_open action. 775 * 776 * Added for backward compatibility to support pre-5.2.0 WordPress versions. 777 * 778 * @since Twenty Twelve 3.0 779 */ 780 function wp_body_open() { 781 /** 782 * Triggered after the opening <body> tag. 783 * 784 * @since Twenty Twelve 3.0 785 */ 786 do_action( 'wp_body_open' ); 787 } 788 endif;
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Tue Sep 22 08:20:31 2026 | Cross-referenced by PHPXref |