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