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