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