[ Index ] |
PHP Cross Reference of WordPress |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Twenty Thirteen functions and definitions 4 * 5 * Sets up the theme and provides some helper functions, which are used in the 6 * theme as custom template tags. Others are attached to action and filter 7 * 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 18 * instead attached 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_Thirteen 24 * @since Twenty Thirteen 1.0 25 */ 26 27 /* 28 * Set up the content width value based on the theme's design. 29 * 30 * @see twentythirteen_content_width() for template-specific adjustments. 31 */ 32 if ( ! isset( $content_width ) ) { 33 $content_width = 604; 34 } 35 36 /** 37 * Add support for a custom header image. 38 */ 39 require get_template_directory() . '/inc/custom-header.php'; 40 41 /** 42 * Twenty Thirteen only works in WordPress 3.6 or later. 43 */ 44 if ( version_compare( $GLOBALS['wp_version'], '3.6-alpha', '<' ) ) { 45 require get_template_directory() . '/inc/back-compat.php'; 46 } 47 48 /** 49 * Block Patterns. 50 * 51 * @since Twenty Thirteen 3.4 52 */ 53 require get_template_directory() . '/inc/block-patterns.php'; 54 55 /** 56 * Twenty Thirteen setup. 57 * 58 * Sets up theme defaults and registers the various WordPress features that 59 * Twenty Thirteen supports. 60 * 61 * @uses load_theme_textdomain() For translation/localization support. 62 * @uses add_editor_style() To add Visual Editor stylesheets. 63 * @uses add_theme_support() To add support for automatic feed links, post 64 * formats, and post thumbnails. 65 * @uses register_nav_menu() To add support for a navigation menu. 66 * @uses set_post_thumbnail_size() To set a custom post thumbnail size. 67 * 68 * @since Twenty Thirteen 1.0 69 */ 70 function twentythirteen_setup() { 71 /* 72 * Makes Twenty Thirteen available for translation. 73 * 74 * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentythirteen 75 * If you're building a theme based on Twenty Thirteen, use a find and 76 * replace to change 'twentythirteen' to the name of your theme in all 77 * template files. 78 */ 79 load_theme_textdomain( 'twentythirteen' ); 80 81 /* 82 * This theme styles the visual editor to resemble the theme style, 83 * specifically font, colors, icons, and column width. 84 */ 85 add_editor_style( array( 'css/editor-style.css', 'genericons/genericons.css', twentythirteen_fonts_url() ) ); 86 87 // Load regular editor styles into the new block-based editor. 88 add_theme_support( 'editor-styles' ); 89 90 // Load default block styles. 91 add_theme_support( 'wp-block-styles' ); 92 93 // Add support for full and wide align images. 94 add_theme_support( 'align-wide' ); 95 96 // Add support for responsive embeds. 97 add_theme_support( 'responsive-embeds' ); 98 99 // Add support for custom color scheme. 100 add_theme_support( 101 'editor-color-palette', 102 array( 103 array( 104 'name' => __( 'Dark Gray', 'twentythirteen' ), 105 'slug' => 'dark-gray', 106 'color' => '#141412', 107 ), 108 array( 109 'name' => __( 'Red', 'twentythirteen' ), 110 'slug' => 'red', 111 'color' => '#bc360a', 112 ), 113 array( 114 'name' => __( 'Medium Orange', 'twentythirteen' ), 115 'slug' => 'medium-orange', 116 'color' => '#db572f', 117 ), 118 array( 119 'name' => __( 'Light Orange', 'twentythirteen' ), 120 'slug' => 'light-orange', 121 'color' => '#ea9629', 122 ), 123 array( 124 'name' => __( 'Yellow', 'twentythirteen' ), 125 'slug' => 'yellow', 126 'color' => '#fbca3c', 127 ), 128 array( 129 'name' => __( 'White', 'twentythirteen' ), 130 'slug' => 'white', 131 'color' => '#fff', 132 ), 133 array( 134 'name' => __( 'Dark Brown', 'twentythirteen' ), 135 'slug' => 'dark-brown', 136 'color' => '#220e10', 137 ), 138 array( 139 'name' => __( 'Medium Brown', 'twentythirteen' ), 140 'slug' => 'medium-brown', 141 'color' => '#722d19', 142 ), 143 array( 144 'name' => __( 'Light Brown', 'twentythirteen' ), 145 'slug' => 'light-brown', 146 'color' => '#eadaa6', 147 ), 148 array( 149 'name' => __( 'Beige', 'twentythirteen' ), 150 'slug' => 'beige', 151 'color' => '#e8e5ce', 152 ), 153 array( 154 'name' => __( 'Off-white', 'twentythirteen' ), 155 'slug' => 'off-white', 156 'color' => '#f7f5e7', 157 ), 158 ) 159 ); 160 161 // Add support for block gradient colors. 162 add_theme_support( 163 'editor-gradient-presets', 164 array( 165 array( 166 'name' => __( 'Autumn Brown', 'twentythirteen' ), 167 'gradient' => 'linear-gradient(135deg, rgba(226,45,15,1) 0%, rgba(158,25,13,1) 100%)', 168 'slug' => 'autumn-brown', 169 ), 170 array( 171 'name' => __( 'Sunset Yellow', 'twentythirteen' ), 172 'gradient' => 'linear-gradient(135deg, rgba(233,139,41,1) 0%, rgba(238,179,95,1) 100%)', 173 'slug' => 'sunset-yellow', 174 ), 175 array( 176 'name' => __( 'Light Sky', 'twentythirteen' ), 177 'gradient' => 'linear-gradient(135deg,rgba(228,228,228,1.0) 0%,rgba(208,225,252,1.0) 100%)', 178 'slug' => 'light-sky', 179 ), 180 array( 181 'name' => __( 'Dark Sky', 'twentythirteen' ), 182 'gradient' => 'linear-gradient(135deg,rgba(0,0,0,1.0) 0%,rgba(56,61,69,1.0) 100%)', 183 'slug' => 'dark-sky', 184 ), 185 ) 186 ); 187 188 // Adds RSS feed links to <head> for posts and comments. 189 add_theme_support( 'automatic-feed-links' ); 190 191 /* 192 * Switches default core markup for search form, comment form, 193 * and comments to output valid HTML5. 194 */ 195 add_theme_support( 196 'html5', 197 array( 198 'search-form', 199 'comment-form', 200 'comment-list', 201 'gallery', 202 'caption', 203 'script', 204 'style', 205 'navigation-widgets', 206 ) 207 ); 208 209 /* 210 * This theme supports all available post formats by default. 211 * See https://wordpress.org/support/article/post-formats/ 212 */ 213 add_theme_support( 214 'post-formats', 215 array( 216 'aside', 217 'audio', 218 'chat', 219 'gallery', 220 'image', 221 'link', 222 'quote', 223 'status', 224 'video', 225 ) 226 ); 227 228 // This theme uses wp_nav_menu() in one location. 229 register_nav_menu( 'primary', __( 'Navigation Menu', 'twentythirteen' ) ); 230 231 /* 232 * This theme uses a custom image size for featured images, displayed on 233 * "standard" posts and pages. 234 */ 235 add_theme_support( 'post-thumbnails' ); 236 set_post_thumbnail_size( 604, 270, true ); 237 238 // This theme uses its own gallery styles. 239 add_filter( 'use_default_gallery_style', '__return_false' ); 240 241 // Indicate widget sidebars can use selective refresh in the Customizer. 242 add_theme_support( 'customize-selective-refresh-widgets' ); 243 } 244 add_action( 'after_setup_theme', 'twentythirteen_setup' ); 245 246 /** 247 * Return the Google font stylesheet URL, if available. 248 * 249 * The use of Source Sans Pro and Bitter by default is localized. For languages 250 * that use characters not supported by the font, the font can be disabled. 251 * 252 * @since Twenty Thirteen 1.0 253 * 254 * @return string Font stylesheet or empty string if disabled. 255 */ 256 function twentythirteen_fonts_url() { 257 $fonts_url = ''; 258 259 /* 260 * translators: If there are characters in your language that are not supported 261 * by Source Sans Pro, translate this to 'off'. Do not translate into your own language. 262 */ 263 $source_sans_pro = _x( 'on', 'Source Sans Pro font: on or off', 'twentythirteen' ); 264 265 /* 266 * translators: If there are characters in your language that are not supported 267 * by Bitter, translate this to 'off'. Do not translate into your own language. 268 */ 269 $bitter = _x( 'on', 'Bitter font: on or off', 'twentythirteen' ); 270 271 if ( 'off' !== $source_sans_pro || 'off' !== $bitter ) { 272 $font_families = array(); 273 274 if ( 'off' !== $source_sans_pro ) { 275 $font_families[] = 'Source Sans Pro:300,400,700,300italic,400italic,700italic'; 276 } 277 278 if ( 'off' !== $bitter ) { 279 $font_families[] = 'Bitter:400,700'; 280 } 281 282 $query_args = array( 283 'family' => urlencode( implode( '|', $font_families ) ), 284 'subset' => urlencode( 'latin,latin-ext' ), 285 'display' => urlencode( 'fallback' ), 286 ); 287 $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' ); 288 } 289 290 return $fonts_url; 291 } 292 293 /** 294 * Enqueue scripts and styles for the front end. 295 * 296 * @since Twenty Thirteen 1.0 297 */ 298 function twentythirteen_scripts_styles() { 299 /* 300 * Adds JavaScript to pages with the comment form to support 301 * sites with threaded comments (when in use). 302 */ 303 if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { 304 wp_enqueue_script( 'comment-reply' ); 305 } 306 307 // Adds Masonry to handle vertical alignment of footer widgets. 308 if ( is_active_sidebar( 'sidebar-1' ) ) { 309 wp_enqueue_script( 'jquery-masonry' ); 310 } 311 312 // Loads JavaScript file with functionality specific to Twenty Thirteen. 313 wp_enqueue_script( 'twentythirteen-script', get_template_directory_uri() . '/js/functions.js', array( 'jquery' ), '20171218', true ); 314 315 // Add Source Sans Pro and Bitter fonts, used in the main stylesheet. 316 wp_enqueue_style( 'twentythirteen-fonts', twentythirteen_fonts_url(), array(), null ); 317 318 // Add Genericons font, used in the main stylesheet. 319 wp_enqueue_style( 'genericons', get_template_directory_uri() . '/genericons/genericons.css', array(), '3.0.3' ); 320 321 // Loads our main stylesheet. 322 wp_enqueue_style( 'twentythirteen-style', get_stylesheet_uri(), array(), '20201208' ); 323 324 // Theme block stylesheet. 325 wp_enqueue_style( 'twentythirteen-block-style', get_template_directory_uri() . '/css/blocks.css', array( 'twentythirteen-style' ), '20190102' ); 326 327 // Loads the Internet Explorer specific stylesheet. 328 wp_enqueue_style( 'twentythirteen-ie', get_template_directory_uri() . '/css/ie.css', array( 'twentythirteen-style' ), '20150214' ); 329 wp_style_add_data( 'twentythirteen-ie', 'conditional', 'lt IE 9' ); 330 } 331 add_action( 'wp_enqueue_scripts', 'twentythirteen_scripts_styles' ); 332 333 /** 334 * Add preconnect for Google Fonts. 335 * 336 * @since Twenty Thirteen 2.1 337 * 338 * @param array $urls URLs to print for resource hints. 339 * @param string $relation_type The relation type the URLs are printed. 340 * @return array URLs to print for resource hints. 341 */ 342 function twentythirteen_resource_hints( $urls, $relation_type ) { 343 if ( wp_style_is( 'twentythirteen-fonts', 'queue' ) && 'preconnect' === $relation_type ) { 344 if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '>=' ) ) { 345 $urls[] = array( 346 'href' => 'https://fonts.gstatic.com', 347 'crossorigin', 348 ); 349 } else { 350 $urls[] = 'https://fonts.gstatic.com'; 351 } 352 } 353 354 return $urls; 355 } 356 add_filter( 'wp_resource_hints', 'twentythirteen_resource_hints', 10, 2 ); 357 358 /** 359 * Enqueue styles for the block-based editor. 360 * 361 * @since Twenty Thirteen 2.5 362 */ 363 function twentythirteen_block_editor_styles() { 364 // Block styles. 365 wp_enqueue_style( 'twentythirteen-block-editor-style', get_template_directory_uri() . '/css/editor-blocks.css', array(), '20201208' ); 366 // Add custom fonts. 367 wp_enqueue_style( 'twentythirteen-fonts', twentythirteen_fonts_url(), array(), null ); 368 } 369 add_action( 'enqueue_block_editor_assets', 'twentythirteen_block_editor_styles' ); 370 371 /** 372 * Filter the page title. 373 * 374 * Creates a nicely formatted and more specific title element text for output 375 * in head of document, based on current view. 376 * 377 * @since Twenty Thirteen 1.0 378 * 379 * @param string $title Default title text for current view. 380 * @param string $sep Optional separator. 381 * @return string The filtered title. 382 */ 383 function twentythirteen_wp_title( $title, $sep ) { 384 global $paged, $page; 385 386 if ( is_feed() ) { 387 return $title; 388 } 389 390 // Add the site name. 391 $title .= get_bloginfo( 'name', 'display' ); 392 393 // Add the site description for the home/front page. 394 $site_description = get_bloginfo( 'description', 'display' ); 395 if ( $site_description && ( is_home() || is_front_page() ) ) { 396 $title = "$title $sep $site_description"; 397 } 398 399 // Add a page number if necessary. 400 if ( ( $paged >= 2 || $page >= 2 ) && ! is_404() ) { 401 /* translators: %s: Page number. */ 402 $title = "$title $sep " . sprintf( __( 'Page %s', 'twentythirteen' ), max( $paged, $page ) ); 403 } 404 405 return $title; 406 } 407 add_filter( 'wp_title', 'twentythirteen_wp_title', 10, 2 ); 408 409 /** 410 * Register two widget areas. 411 * 412 * @since Twenty Thirteen 1.0 413 */ 414 function twentythirteen_widgets_init() { 415 register_sidebar( 416 array( 417 'name' => __( 'Main Widget Area', 'twentythirteen' ), 418 'id' => 'sidebar-1', 419 'description' => __( 'Appears in the footer section of the site.', 'twentythirteen' ), 420 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 421 'after_widget' => '</aside>', 422 'before_title' => '<h3 class="widget-title">', 423 'after_title' => '</h3>', 424 ) 425 ); 426 427 register_sidebar( 428 array( 429 'name' => __( 'Secondary Widget Area', 'twentythirteen' ), 430 'id' => 'sidebar-2', 431 'description' => __( 'Appears on posts and pages in the sidebar.', 'twentythirteen' ), 432 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 433 'after_widget' => '</aside>', 434 'before_title' => '<h3 class="widget-title">', 435 'after_title' => '</h3>', 436 ) 437 ); 438 } 439 add_action( 'widgets_init', 'twentythirteen_widgets_init' ); 440 441 if ( ! function_exists( 'wp_get_list_item_separator' ) ) : 442 /** 443 * Retrieves the list item separator based on the locale. 444 * 445 * Added for backward compatibility to support pre-6.0.0 WordPress versions. 446 * 447 * @since 6.0.0 448 */ 449 function wp_get_list_item_separator() { 450 /* translators: Used between list items, there is a space after the comma. */ 451 return __( ', ', 'twentythirteen' ); 452 } 453 endif; 454 455 if ( ! function_exists( 'twentythirteen_paging_nav' ) ) : 456 /** 457 * Display navigation to next/previous set of posts when applicable. 458 * 459 * @since Twenty Thirteen 1.0 460 */ 461 function twentythirteen_paging_nav() { 462 global $wp_query; 463 464 // Don't print empty markup if there's only one page. 465 if ( $wp_query->max_num_pages < 2 ) { 466 return; 467 } 468 ?> 469 <nav class="navigation paging-navigation"> 470 <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'twentythirteen' ); ?></h1> 471 <div class="nav-links"> 472 473 <?php if ( get_next_posts_link() ) : ?> 474 <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">←</span> Older posts', 'twentythirteen' ) ); ?></div> 475 <?php endif; ?> 476 477 <?php if ( get_previous_posts_link() ) : ?> 478 <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">→</span>', 'twentythirteen' ) ); ?></div> 479 <?php endif; ?> 480 481 </div><!-- .nav-links --> 482 </nav><!-- .navigation --> 483 <?php 484 } 485 endif; 486 487 if ( ! function_exists( 'twentythirteen_post_nav' ) ) : 488 /** 489 * Display navigation to next/previous post when applicable. 490 * 491 * @since Twenty Thirteen 1.0 492 */ 493 function twentythirteen_post_nav() { 494 global $post; 495 496 // Don't print empty markup if there's nowhere to navigate. 497 $previous = ( is_attachment() ) ? get_post( $post->post_parent ) : get_adjacent_post( false, '', true ); 498 $next = get_adjacent_post( false, '', false ); 499 500 if ( ! $next && ! $previous ) { 501 return; 502 } 503 ?> 504 <nav class="navigation post-navigation"> 505 <h1 class="screen-reader-text"><?php _e( 'Post navigation', 'twentythirteen' ); ?></h1> 506 <div class="nav-links"> 507 508 <?php previous_post_link( '%link', _x( '<span class="meta-nav">←</span> %title', 'Previous post link', 'twentythirteen' ) ); ?> 509 <?php next_post_link( '%link', _x( '%title <span class="meta-nav">→</span>', 'Next post link', 'twentythirteen' ) ); ?> 510 511 </div><!-- .nav-links --> 512 </nav><!-- .navigation --> 513 <?php 514 } 515 endif; 516 517 if ( ! function_exists( 'twentythirteen_entry_meta' ) ) : 518 /** 519 * Print HTML with meta information for current post: categories, tags, permalink, author, and date. 520 * 521 * Create your own twentythirteen_entry_meta() to override in a child theme. 522 * 523 * @since Twenty Thirteen 1.0 524 */ 525 function twentythirteen_entry_meta() { 526 if ( is_sticky() && is_home() && ! is_paged() ) { 527 echo '<span class="featured-post">' . esc_html__( 'Sticky', 'twentythirteen' ) . '</span>'; 528 } 529 530 if ( ! has_post_format( 'link' ) && 'post' === get_post_type() ) { 531 twentythirteen_entry_date(); 532 } 533 534 $categories_list = get_the_category_list( wp_get_list_item_separator() ); 535 if ( $categories_list ) { 536 echo '<span class="categories-links">' . $categories_list . '</span>'; 537 } 538 539 $tags_list = get_the_tag_list( '', wp_get_list_item_separator() ); 540 if ( $tags_list && ! is_wp_error( $tags_list ) ) { 541 echo '<span class="tags-links">' . $tags_list . '</span>'; 542 } 543 544 // Post author. 545 if ( 'post' === get_post_type() ) { 546 printf( 547 '<span class="author vcard"><a class="url fn n" href="%1$s" title="%2$s" rel="author">%3$s</a></span>', 548 esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ), 549 /* translators: %s: Author display name. */ 550 esc_attr( sprintf( __( 'View all posts by %s', 'twentythirteen' ), get_the_author() ) ), 551 get_the_author() 552 ); 553 } 554 } 555 endif; 556 557 if ( ! function_exists( 'twentythirteen_entry_date' ) ) : 558 /** 559 * Print HTML with date information for current post. 560 * 561 * Create your own twentythirteen_entry_date() to override in a child theme. 562 * 563 * @since Twenty Thirteen 1.0 564 * 565 * @param bool $display (optional) Whether to display the date. Default true. 566 * @return string The HTML-formatted post date. 567 */ 568 function twentythirteen_entry_date( $display = true ) { 569 if ( has_post_format( array( 'chat', 'status' ) ) ) { 570 /* translators: 1: Post format name, 2: Date. */ 571 $format_prefix = _x( '%1$s on %2$s', '1: post format name. 2: date', 'twentythirteen' ); 572 } else { 573 $format_prefix = '%2$s'; 574 } 575 576 $date = sprintf( 577 '<span class="date"><a href="%1$s" title="%2$s" rel="bookmark"><time class="entry-date" datetime="%3$s">%4$s</time></a></span>', 578 esc_url( get_permalink() ), 579 /* translators: %s: Post title. */ 580 esc_attr( sprintf( __( 'Permalink to %s', 'twentythirteen' ), the_title_attribute( 'echo=0' ) ) ), 581 esc_attr( get_the_date( 'c' ) ), 582 esc_html( sprintf( $format_prefix, get_post_format_string( get_post_format() ), get_the_date() ) ) 583 ); 584 585 if ( $display ) { 586 echo $date; 587 } 588 589 return $date; 590 } 591 endif; 592 593 if ( ! function_exists( 'twentythirteen_the_attached_image' ) ) : 594 /** 595 * Print the attached image with a link to the next attached image. 596 * 597 * @since Twenty Thirteen 1.0 598 */ 599 function twentythirteen_the_attached_image() { 600 /** 601 * Filters the image attachment size to use. 602 * 603 * @since Twenty thirteen 1.0 604 * 605 * @param array $size { 606 * @type int The attachment height in pixels. 607 * @type int The attachment width in pixels. 608 * } 609 */ 610 $attachment_size = apply_filters( 'twentythirteen_attachment_size', array( 724, 724 ) ); 611 $next_attachment_url = wp_get_attachment_url(); 612 $post = get_post(); 613 614 /* 615 * Grab the IDs of all the image attachments in a gallery so we can get the URL 616 * of the next adjacent image in a gallery, or the first image (if we're 617 * looking at the last image in a gallery), or, in a gallery of one, just the 618 * link to that image file. 619 */ 620 $attachment_ids = get_posts( 621 array( 622 'post_parent' => $post->post_parent, 623 'fields' => 'ids', 624 'numberposts' => -1, 625 'post_status' => 'inherit', 626 'post_type' => 'attachment', 627 'post_mime_type' => 'image', 628 'order' => 'ASC', 629 'orderby' => 'menu_order ID', 630 ) 631 ); 632 633 // If there is more than 1 attachment in a gallery... 634 if ( count( $attachment_ids ) > 1 ) { 635 foreach ( $attachment_ids as $idx => $attachment_id ) { 636 if ( $attachment_id == $post->ID ) { 637 $next_id = $attachment_ids[ ( $idx + 1 ) % count( $attachment_ids ) ]; 638 break; 639 } 640 } 641 642 if ( $next_id ) { 643 // ...get the URL of the next image attachment. 644 $next_attachment_url = get_attachment_link( $next_id ); 645 } else { 646 // ...or get the URL of the first image attachment. 647 $next_attachment_url = get_attachment_link( reset( $attachment_ids ) ); 648 } 649 } 650 651 printf( 652 '<a href="%1$s" title="%2$s" rel="attachment">%3$s</a>', 653 esc_url( $next_attachment_url ), 654 the_title_attribute( array( 'echo' => false ) ), 655 wp_get_attachment_image( $post->ID, $attachment_size ) 656 ); 657 } 658 endif; 659 660 /** 661 * Return the post URL. 662 * 663 * @uses get_url_in_content() to get the URL in the post meta (if it exists) or 664 * the first link found in the post content. 665 * 666 * Falls back to the post permalink if no URL is found in the post. 667 * 668 * @since Twenty Thirteen 1.0 669 * 670 * @return string The Link format URL. 671 */ 672 function twentythirteen_get_link_url() { 673 $content = get_the_content(); 674 $has_url = get_url_in_content( $content ); 675 676 return ( $has_url ) ? $has_url : apply_filters( 'the_permalink', get_permalink() ); 677 } 678 679 if ( ! function_exists( 'twentythirteen_excerpt_more' ) && ! is_admin() ) : 680 /** 681 * Replaces "[...]" (appended to automatically generated excerpts) with ... 682 * and a Continue reading link. 683 * 684 * @since Twenty Thirteen 1.4 685 * 686 * @param string $more Default Read More excerpt link. 687 * @return string Filtered Read More excerpt link. 688 */ 689 function twentythirteen_excerpt_more( $more ) { 690 $link = sprintf( 691 '<a href="%1$s" class="more-link">%2$s</a>', 692 esc_url( get_permalink( get_the_ID() ) ), 693 /* translators: %s: Post title. Only visible to screen readers. */ 694 sprintf( __( 'Continue reading %s <span class="meta-nav">→</span>', 'twentythirteen' ), '<span class="screen-reader-text">' . get_the_title( get_the_ID() ) . '</span>' ) 695 ); 696 return ' … ' . $link; 697 } 698 add_filter( 'excerpt_more', 'twentythirteen_excerpt_more' ); 699 endif; 700 701 /** 702 * Extend the default WordPress body classes. 703 * 704 * Adds body classes to denote: 705 * 1. Single or multiple authors. 706 * 2. Active widgets in the sidebar to change the layout and spacing. 707 * 3. When avatars are disabled in discussion settings. 708 * 709 * @since Twenty Thirteen 1.0 710 * 711 * @param array $classes A list of existing body class values. 712 * @return array The filtered body class list. 713 */ 714 function twentythirteen_body_class( $classes ) { 715 if ( ! is_multi_author() ) { 716 $classes[] = 'single-author'; 717 } 718 719 if ( is_active_sidebar( 'sidebar-2' ) && ! is_attachment() && ! is_404() ) { 720 $classes[] = 'sidebar'; 721 } 722 723 if ( ! get_option( 'show_avatars' ) ) { 724 $classes[] = 'no-avatars'; 725 } 726 727 return $classes; 728 } 729 add_filter( 'body_class', 'twentythirteen_body_class' ); 730 731 /** 732 * Adjust content_width value for video post formats and attachment templates. 733 * 734 * @since Twenty Thirteen 1.0 735 */ 736 function twentythirteen_content_width() { 737 global $content_width; 738 739 if ( is_attachment() ) { 740 $content_width = 724; 741 } elseif ( has_post_format( 'audio' ) ) { 742 $content_width = 484; 743 } 744 } 745 add_action( 'template_redirect', 'twentythirteen_content_width' ); 746 747 /** 748 * Add postMessage support for site title and description for the Customizer. 749 * 750 * @since Twenty Thirteen 1.0 751 * 752 * @param WP_Customize_Manager $wp_customize Customizer object. 753 */ 754 function twentythirteen_customize_register( $wp_customize ) { 755 $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; 756 $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; 757 $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; 758 759 if ( isset( $wp_customize->selective_refresh ) ) { 760 $wp_customize->selective_refresh->add_partial( 761 'blogname', 762 array( 763 'selector' => '.site-title', 764 'container_inclusive' => false, 765 'render_callback' => 'twentythirteen_customize_partial_blogname', 766 ) 767 ); 768 $wp_customize->selective_refresh->add_partial( 769 'blogdescription', 770 array( 771 'selector' => '.site-description', 772 'container_inclusive' => false, 773 'render_callback' => 'twentythirteen_customize_partial_blogdescription', 774 ) 775 ); 776 } 777 } 778 add_action( 'customize_register', 'twentythirteen_customize_register' ); 779 780 /** 781 * Render the site title for the selective refresh partial. 782 * 783 * @since Twenty Thirteen 1.9 784 * 785 * @see twentythirteen_customize_register() 786 * 787 * @return void 788 */ 789 function twentythirteen_customize_partial_blogname() { 790 bloginfo( 'name' ); 791 } 792 793 /** 794 * Render the site tagline for the selective refresh partial. 795 * 796 * @since Twenty Thirteen 1.9 797 * 798 * @see twentythirteen_customize_register() 799 * 800 * @return void 801 */ 802 function twentythirteen_customize_partial_blogdescription() { 803 bloginfo( 'description' ); 804 } 805 806 /** 807 * Enqueue JavaScript postMessage handlers for the Customizer. 808 * 809 * Binds JavaScript handlers to make the Customizer preview 810 * reload changes asynchronously. 811 * 812 * @since Twenty Thirteen 1.0 813 */ 814 function twentythirteen_customize_preview_js() { 815 wp_enqueue_script( 'twentythirteen-customizer', get_template_directory_uri() . '/js/theme-customizer.js', array( 'customize-preview' ), '20141120', true ); 816 } 817 add_action( 'customize_preview_init', 'twentythirteen_customize_preview_js' ); 818 819 /** 820 * Modifies tag cloud widget arguments to display all tags in the same font size 821 * and use list format for better accessibility. 822 * 823 * @since Twenty Thirteen 2.3 824 * 825 * @param array $args Arguments for tag cloud widget. 826 * @return array The filtered arguments for tag cloud widget. 827 */ 828 function twentythirteen_widget_tag_cloud_args( $args ) { 829 $args['largest'] = 22; 830 $args['smallest'] = 8; 831 $args['unit'] = 'pt'; 832 $args['format'] = 'list'; 833 834 return $args; 835 } 836 add_filter( 'widget_tag_cloud_args', 'twentythirteen_widget_tag_cloud_args' ); 837 838 /** 839 * Prevents `author-bio.php` partial template from interfering with rendering 840 * an author archive of a user with the `bio` username. 841 * 842 * @since Twenty Thirteen 3.0 843 * 844 * @param string $template Template file. 845 * @return string Replacement template file. 846 */ 847 function twentythirteen_author_bio_template( $template ) { 848 if ( is_author() ) { 849 $author = get_queried_object(); 850 if ( $author instanceof WP_User && 'bio' === $author->user_nicename ) { 851 // Use author templates if exist, fall back to template hierarchy otherwise. 852 return locate_template( array( "author-{$author->ID}.php", 'author.php' ) ); 853 } 854 } 855 856 return $template; 857 } 858 add_filter( 'author_template', 'twentythirteen_author_bio_template' ); 859 860 if ( ! function_exists( 'wp_body_open' ) ) : 861 /** 862 * Fire the wp_body_open action. 863 * 864 * Added for backward compatibility to support pre-5.2.0 WordPress versions. 865 * 866 * @since Twenty Thirteen 2.8 867 */ 868 function wp_body_open() { 869 /** 870 * Triggered after the opening <body> tag. 871 * 872 * @since Twenty Thirteen 2.8 873 */ 874 do_action( 'wp_body_open' ); 875 } 876 endif; 877 878 /** 879 * Register Custom Block Styles 880 * 881 * @since Twenty Thirteen 3.4 882 */ 883 if ( function_exists( 'register_block_style' ) ) { 884 function twentythirteen_register_block_styles() { 885 886 /** 887 * Register block style 888 */ 889 register_block_style( 890 'core/button', 891 array( 892 'name' => 'no-shadow', 893 'label' => __( 'No Shadow', 'twentythirteen' ), 894 'style_handle' => 'no-shadow', 895 ) 896 ); 897 } 898 add_action( 'init', 'twentythirteen_register_block_styles' ); 899 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Nov 6 01:00:02 2024 | Cross-referenced by PHPXref 0.7.1 |