| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Custom template tags for this theme. 4 * 5 * @package WordPress 6 * @subpackage Twenty_Twenty 7 * @since Twenty Twenty 1.0 8 */ 9 10 /** 11 * Table of Contents: 12 * Logo & Description 13 * Comments 14 * Post Meta 15 * Menus 16 * Classes 17 * Archives 18 * Miscellaneous 19 */ 20 21 /** 22 * Logo & Description 23 */ 24 25 /** 26 * Displays the site logo, either text or image. 27 * 28 * @since Twenty Twenty 1.0 29 * 30 * @param array $args Arguments for displaying the site logo either as an image or text. 31 * @param bool $display Display or return the HTML. 32 * @return string|void Compiled HTML based on our arguments. 33 */ 34 function twentytwenty_site_logo( $args = array(), $display = true ) { 35 $logo = get_custom_logo(); 36 $site_title = get_bloginfo( 'name' ); 37 $contents = ''; 38 $classname = ''; 39 40 $defaults = array( 41 'logo' => '%1$s<span class="screen-reader-text">%2$s</span>', 42 'logo_class' => 'site-logo', 43 'title' => '<a href="%1$s" rel="home">%2$s</a>', 44 'title_class' => 'site-title', 45 'home_wrap' => '<h1 class="%1$s">%2$s</h1>', 46 'single_wrap' => '<div class="%1$s faux-heading">%2$s</div>', 47 'condition' => ( is_front_page() || is_home() ) && ! is_page(), 48 ); 49 50 $args = wp_parse_args( $args, $defaults ); 51 52 /** 53 * Filters the arguments for `twentytwenty_site_logo()`. 54 * 55 * @since Twenty Twenty 1.0 56 * 57 * @param array $args Parsed arguments. 58 * @param array $defaults Function's default arguments. 59 */ 60 $args = apply_filters( 'twentytwenty_site_logo_args', $args, $defaults ); 61 62 if ( has_custom_logo() ) { 63 $contents = sprintf( $args['logo'], $logo, esc_html( $site_title ) ); 64 $classname = $args['logo_class']; 65 } else { 66 if ( ! $site_title ) { 67 return ''; 68 } 69 70 $contents = sprintf( $args['title'], esc_url( get_home_url( null, '/' ) ), esc_html( $site_title ) ); 71 if ( 72 ( is_front_page() || is_home() && ( (int) get_option( 'page_for_posts' ) !== get_queried_object_id() ) ) 73 && ! is_paged() 74 && $args['title'] === $defaults['title'] 75 ) { 76 $contents = str_replace( ' rel=', ' aria-current="page" rel=', $contents ); 77 } 78 $classname = $args['title_class']; 79 } 80 81 $wrap = $args['condition'] ? 'home_wrap' : 'single_wrap'; 82 83 $html = sprintf( $args[ $wrap ], $classname, $contents ); 84 85 /** 86 * Filters the arguments for `twentytwenty_site_logo()`. 87 * 88 * @since Twenty Twenty 1.0 89 * 90 * @param string $html Compiled HTML based on our arguments. 91 * @param array $args Parsed arguments. 92 * @param string $classname Class name based on current view, home or single. 93 * @param string $contents HTML for site title or logo. 94 */ 95 $html = apply_filters( 'twentytwenty_site_logo', $html, $args, $classname, $contents ); 96 97 if ( ! $display ) { 98 return $html; 99 } 100 101 echo $html; 102 } 103 104 /** 105 * Displays the site description. 106 * 107 * @since Twenty Twenty 1.0 108 * 109 * @param bool $display Display or return the HTML. 110 * @return string|null|void The HTML when `$display` is false, null when the site has no 111 * description. Nothing otherwise. 112 * @phpstan-return ( $display is true ? void : string|null ) 113 */ 114 function twentytwenty_site_description( $display = true ) { 115 $description = get_bloginfo( 'description' ); 116 117 if ( ! $description ) { 118 return null; 119 } 120 121 $wrapper = '<div class="site-description">%s</div><!-- .site-description -->'; 122 123 $html = sprintf( $wrapper, esc_html( $description ) ); 124 125 /** 126 * Filters the HTML for the site description. 127 * 128 * @since Twenty Twenty 1.0 129 * 130 * @param string $html The HTML to display. 131 * @param string $description Site description via `bloginfo()`. 132 * @param string $wrapper The format used in case you want to reuse it in a `sprintf()`. 133 */ 134 $html = apply_filters( 'twentytwenty_site_description', $html, $description, $wrapper ); 135 136 if ( ! $display ) { 137 return $html; 138 } 139 140 echo $html; 141 } 142 143 /** 144 * Comments 145 */ 146 147 /** 148 * Checks if the specified comment is written by the author of the post commented on. 149 * 150 * @since Twenty Twenty 1.0 151 * 152 * @param object $comment Comment data. 153 * @return bool Whether the comment is by the post author. 154 */ 155 function twentytwenty_is_comment_by_post_author( $comment = null ) { 156 157 if ( is_object( $comment ) && $comment->user_id > 0 ) { 158 159 $user = get_userdata( $comment->user_id ); 160 $post = get_post( $comment->comment_post_ID ); 161 162 if ( ! empty( $user ) && ! empty( $post ) ) { 163 164 return $comment->user_id === $post->post_author; 165 166 } 167 } 168 return false; 169 } 170 171 /** 172 * Filters comment reply link to not JS scroll. 173 * 174 * Filters the comment reply link to add a class indicating it should not use JS slow-scroll, as it 175 * makes it scroll to the wrong position on the page. 176 * 177 * @since Twenty Twenty 1.0 178 * 179 * @param string $link Link to the top of the page. 180 * @return string Link to the top of the page. 181 */ 182 function twentytwenty_filter_comment_reply_link( $link ) { 183 184 $link = str_replace( 'class=\'', 'class=\'do-not-scroll ', $link ); 185 return $link; 186 } 187 188 add_filter( 'comment_reply_link', 'twentytwenty_filter_comment_reply_link' ); 189 190 /** 191 * Post Meta 192 */ 193 194 /** 195 * Retrieves and displays the post meta. 196 * 197 * If it's a single post, outputs the post meta values specified in the Customizer settings. 198 * 199 * @since Twenty Twenty 1.0 200 * 201 * @param int $post_id The ID of the post for which the post meta should be output. 202 * @param string $location Which post meta location to output – single or preview. 203 */ 204 function twentytwenty_the_post_meta( $post_id = null, $location = 'single-top' ) { 205 206 echo twentytwenty_get_post_meta( $post_id, $location ); 207 } 208 209 /** 210 * Filters the edit post link to add an icon and use the post meta structure. 211 * 212 * @since Twenty Twenty 1.0 213 * 214 * @param string $link Anchor tag for the edit link. 215 * @param int $post_id Post ID. 216 * @param string $text Anchor text. 217 */ 218 function twentytwenty_edit_post_link( $link, $post_id, $text ) { 219 if ( is_admin() ) { 220 return $link; 221 } 222 223 $edit_url = get_edit_post_link( $post_id ); 224 225 if ( ! $edit_url ) { 226 return; 227 } 228 229 $text = sprintf( 230 wp_kses( 231 /* translators: %s: Post title. Only visible to screen readers. */ 232 __( 'Edit <span class="screen-reader-text">%s</span>', 'twentytwenty' ), 233 array( 234 'span' => array( 235 'class' => array(), 236 ), 237 ) 238 ), 239 get_the_title( $post_id ) 240 ); 241 242 return '<div class="post-meta-wrapper post-meta-edit-link-wrapper"><ul class="post-meta"><li class="post-edit meta-wrapper"><span class="meta-icon">' . twentytwenty_get_theme_svg( 'edit' ) . '</span><span class="meta-text"><a href="' . esc_url( $edit_url ) . '">' . $text . '</a></span></li></ul><!-- .post-meta --></div><!-- .post-meta-wrapper -->'; 243 } 244 245 add_filter( 'edit_post_link', 'twentytwenty_edit_post_link', 10, 3 ); 246 247 /** 248 * Retrieves the post meta. 249 * 250 * @since Twenty Twenty 1.0 251 * 252 * @param int $post_id The ID of the post. 253 * @param string $location The location where the meta is shown. 254 * @return string|void Post meta HTML. 255 */ 256 function twentytwenty_get_post_meta( $post_id = null, $location = 'single-top' ) { 257 258 // Require post ID. 259 if ( ! $post_id ) { 260 return; 261 } 262 263 /** 264 * Filters post types array. 265 * 266 * This filter can be used to hide post meta information of post, page or custom post type 267 * registered by child themes or plugins. 268 * 269 * @since Twenty Twenty 1.0 270 * 271 * @param array $post_types Array of post types. 272 */ 273 $disallowed_post_types = apply_filters( 'twentytwenty_disallowed_post_types_for_meta_output', array( 'page' ) ); 274 275 // Check whether the post type is allowed to output post meta. 276 if ( in_array( get_post_type( $post_id ), $disallowed_post_types, true ) ) { 277 return; 278 } 279 280 $post_meta_wrapper_classes = ''; 281 $post_meta_classes = ''; 282 283 // Get the post meta settings for the location specified. 284 if ( 'single-top' === $location ) { 285 /** 286 * Filters post meta info visibility. 287 * 288 * Use this filter to hide post meta information like Author, Post date, Comments, Is sticky status. 289 * 290 * @since Twenty Twenty 1.0 291 * 292 * @param array $args { 293 * @type string $author 294 * @type string $post-date 295 * @type string $comments 296 * @type string $sticky 297 * } 298 */ 299 $post_meta = apply_filters( 300 'twentytwenty_post_meta_location_single_top', 301 array( 302 'author', 303 'post-date', 304 'comments', 305 'sticky', 306 ) 307 ); 308 309 $post_meta_wrapper_classes = ' post-meta-single post-meta-single-top'; 310 311 } elseif ( 'single-bottom' === $location ) { 312 313 /** 314 * Filters post tags visibility. 315 * 316 * Use this filter to hide post tags. 317 * 318 * @since Twenty Twenty 1.0 319 * 320 * @param array $args { 321 * @type string $tags 322 * } 323 */ 324 $post_meta = apply_filters( 325 'twentytwenty_post_meta_location_single_bottom', 326 array( 327 'tags', 328 ) 329 ); 330 331 $post_meta_wrapper_classes = ' post-meta-single post-meta-single-bottom'; 332 333 } 334 335 // If the post meta setting has the value 'empty', it's explicitly empty and the default post meta shouldn't be output. 336 if ( $post_meta && ! in_array( 'empty', $post_meta, true ) ) { 337 338 // Make sure we don't output an empty container. 339 $has_meta = false; 340 341 $the_post = get_post( $post_id ); 342 setup_postdata( $the_post ); 343 344 ob_start(); 345 346 ?> 347 348 <div class="post-meta-wrapper<?php echo esc_attr( $post_meta_wrapper_classes ); ?>"> 349 350 <ul class="post-meta<?php echo esc_attr( $post_meta_classes ); ?>"> 351 352 <?php 353 354 /** 355 * Fires before post meta HTML display. 356 * 357 * Allow output of additional post meta info to be added by child themes and plugins. 358 * 359 * @since Twenty Twenty 1.0 360 * @since Twenty Twenty 1.1 Added the `$post_meta` and `$location` parameters. 361 * 362 * @param int $post_id Post ID. 363 * @param array $post_meta An array of post meta information. 364 * @param string $location The location where the meta is shown. 365 * Accepts 'single-top' or 'single-bottom'. 366 */ 367 do_action( 'twentytwenty_start_of_post_meta_list', $post_id, $post_meta, $location ); 368 369 // Author. 370 if ( post_type_supports( get_post_type( $post_id ), 'author' ) && in_array( 'author', $post_meta, true ) ) { 371 372 $has_meta = true; 373 ?> 374 <li class="post-author meta-wrapper"> 375 <span class="meta-icon"> 376 <span class="screen-reader-text"> 377 <?php 378 /* translators: Hidden accessibility text. */ 379 _e( 'Post author', 'twentytwenty' ); 380 ?> 381 </span> 382 <?php twentytwenty_the_theme_svg( 'user' ); ?> 383 </span> 384 <span class="meta-text"> 385 <?php 386 printf( 387 /* translators: %s: Author name. */ 388 __( 'By %s', 'twentytwenty' ), 389 '<a href="' . esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ) . '">' . esc_html( get_the_author_meta( 'display_name' ) ) . '</a>' 390 ); 391 ?> 392 </span> 393 </li> 394 <?php 395 396 } 397 398 // Post date. 399 if ( in_array( 'post-date', $post_meta, true ) ) { 400 401 $has_meta = true; 402 ?> 403 <li class="post-date meta-wrapper"> 404 <span class="meta-icon"> 405 <span class="screen-reader-text"> 406 <?php 407 /* translators: Hidden accessibility text. */ 408 _e( 'Post date', 'twentytwenty' ); 409 ?> 410 </span> 411 <?php twentytwenty_the_theme_svg( 'calendar' ); ?> 412 </span> 413 <span class="meta-text"> 414 <a href="<?php the_permalink(); ?>"><?php the_time( get_option( 'date_format' ) ); ?></a> 415 </span> 416 </li> 417 <?php 418 419 } 420 421 // Categories. 422 if ( in_array( 'categories', $post_meta, true ) && has_category() ) { 423 424 $has_meta = true; 425 ?> 426 <li class="post-categories meta-wrapper"> 427 <span class="meta-icon"> 428 <span class="screen-reader-text"> 429 <?php 430 /* translators: Hidden accessibility text. */ 431 _e( 'Categories', 'twentytwenty' ); 432 ?> 433 </span> 434 <?php twentytwenty_the_theme_svg( 'folder' ); ?> 435 </span> 436 <span class="meta-text"> 437 <?php _ex( 'In', 'A string that is output before one or more categories', 'twentytwenty' ); ?> <?php the_category( ', ' ); ?> 438 </span> 439 </li> 440 <?php 441 442 } 443 444 // Tags. 445 if ( in_array( 'tags', $post_meta, true ) && has_tag() ) { 446 447 $has_meta = true; 448 ?> 449 <li class="post-tags meta-wrapper"> 450 <span class="meta-icon"> 451 <span class="screen-reader-text"> 452 <?php 453 /* translators: Hidden accessibility text. */ 454 _e( 'Tags', 'twentytwenty' ); 455 ?> 456 </span> 457 <?php twentytwenty_the_theme_svg( 'tag' ); ?> 458 </span> 459 <span class="meta-text"> 460 <?php the_tags( '', ', ', '' ); ?> 461 </span> 462 </li> 463 <?php 464 465 } 466 467 // Comments link. 468 if ( in_array( 'comments', $post_meta, true ) && ! post_password_required() && ( comments_open() || get_comments_number() ) ) { 469 470 $has_meta = true; 471 ?> 472 <li class="post-comment-link meta-wrapper"> 473 <span class="meta-icon"> 474 <?php twentytwenty_the_theme_svg( 'comment' ); ?> 475 </span> 476 <span class="meta-text"> 477 <?php comments_popup_link(); ?> 478 </span> 479 </li> 480 <?php 481 482 } 483 484 // Sticky. 485 if ( in_array( 'sticky', $post_meta, true ) && is_sticky() ) { 486 487 $has_meta = true; 488 ?> 489 <li class="post-sticky meta-wrapper"> 490 <span class="meta-icon"> 491 <?php twentytwenty_the_theme_svg( 'bookmark' ); ?> 492 </span> 493 <span class="meta-text"> 494 <?php _e( 'Sticky post', 'twentytwenty' ); ?> 495 </span> 496 </li> 497 <?php 498 499 } 500 501 /** 502 * Fires after post meta HTML display. 503 * 504 * Allow output of additional post meta info to be added by child themes and plugins. 505 * 506 * @since Twenty Twenty 1.0 507 * @since Twenty Twenty 1.1 Added the `$post_meta` and `$location` parameters. 508 * 509 * @param int $post_id Post ID. 510 * @param array $post_meta An array of post meta information. 511 * @param string $location The location where the meta is shown. 512 * Accepts 'single-top' or 'single-bottom'. 513 */ 514 do_action( 'twentytwenty_end_of_post_meta_list', $post_id, $post_meta, $location ); 515 516 ?> 517 518 </ul><!-- .post-meta --> 519 520 </div><!-- .post-meta-wrapper --> 521 522 <?php 523 524 wp_reset_postdata(); 525 526 $meta_output = ob_get_clean(); 527 528 // If there is meta to output, return it. 529 if ( $has_meta && $meta_output ) { 530 531 return $meta_output; 532 533 } 534 } 535 } 536 537 /** 538 * Menus 539 */ 540 541 /** 542 * Filters classes of wp_list_pages items to match menu items. 543 * 544 * Filters the class applied to wp_list_pages() items with children to match the menu class, to simplify 545 * styling of sub levels in the fallback. Only applied if the match_menu_classes argument is set. 546 * 547 * @since Twenty Twenty 1.0 548 * 549 * @param string[] $css_class An array of CSS classes to be applied to each list item. 550 * @param WP_Post $page Page data object. 551 * @param int $depth Depth of page, used for padding. 552 * @param array $args An array of arguments. 553 * @return array CSS class names. 554 */ 555 function twentytwenty_filter_wp_list_pages_item_classes( $css_class, $page, $depth, $args ) { 556 557 // Only apply to wp_list_pages() calls with match_menu_classes set to true. 558 $match_menu_classes = isset( $args['match_menu_classes'] ); 559 560 if ( ! $match_menu_classes ) { 561 return $css_class; 562 } 563 564 // Add current menu item class. 565 if ( in_array( 'current_page_item', $css_class, true ) ) { 566 $css_class[] = 'current-menu-item'; 567 } 568 569 // Add menu item has children class. 570 if ( in_array( 'page_item_has_children', $css_class, true ) ) { 571 $css_class[] = 'menu-item-has-children'; 572 } 573 574 return $css_class; 575 } 576 577 add_filter( 'page_css_class', 'twentytwenty_filter_wp_list_pages_item_classes', 10, 4 ); 578 579 /** 580 * Adds a Sub Nav Toggle to the Expanded Menu and Mobile Menu. 581 * 582 * @since Twenty Twenty 1.0 583 * 584 * @param stdClass $args An object of wp_nav_menu() arguments. 585 * @param WP_Post $item Menu item data object. 586 * @return stdClass An object of wp_nav_menu() arguments. 587 */ 588 function twentytwenty_add_sub_toggles_to_main_menu( $args, $item ) { 589 590 // Add sub menu toggles to the Expanded Menu with toggles. 591 if ( isset( $args->show_toggles ) && $args->show_toggles ) { 592 593 // Wrap the menu item link contents in a div, used for positioning. 594 $args->before = '<div class="ancestor-wrapper">'; 595 $args->after = ''; 596 597 // Add a toggle to items with children. 598 if ( in_array( 'menu-item-has-children', $item->classes, true ) ) { 599 600 $toggle_target_string = '.menu-modal .menu-item-' . $item->ID . ' > .sub-menu'; 601 $toggle_duration = twentytwenty_toggle_duration(); 602 603 // Add the sub menu toggle. 604 $args->after .= '<button class="toggle sub-menu-toggle fill-children-current-color" data-toggle-target="' . $toggle_target_string . '" data-toggle-type="slidetoggle" data-toggle-duration="' . absint( $toggle_duration ) . '" aria-expanded="false"><span class="screen-reader-text">' . 605 /* translators: Hidden accessibility text. */ 606 __( 'Show sub menu', 'twentytwenty' ) . 607 '</span>' . twentytwenty_get_theme_svg( 'chevron-down' ) . '</button>'; 608 609 } 610 611 // Close the wrapper. 612 $args->after .= '</div><!-- .ancestor-wrapper -->'; 613 614 // Add sub menu icons to the primary menu without toggles. 615 } elseif ( 'primary' === $args->theme_location ) { 616 if ( in_array( 'menu-item-has-children', $item->classes, true ) ) { 617 $args->after = '<span class="icon"></span>'; 618 } else { 619 $args->after = ''; 620 } 621 } 622 623 return $args; 624 } 625 626 add_filter( 'nav_menu_item_args', 'twentytwenty_add_sub_toggles_to_main_menu', 10, 2 ); 627 628 /** 629 * Displays SVG icons in social links menu. 630 * 631 * @since Twenty Twenty 1.0 632 * 633 * @param string $item_output The menu item's starting HTML output. 634 * @param WP_Post $item Menu item data object. 635 * @param int $depth Depth of the menu. Used for padding. 636 * @param stdClass $args An object of wp_nav_menu() arguments. 637 * @return string The menu item output with social icon. 638 */ 639 function twentytwenty_nav_menu_social_icons( $item_output, $item, $depth, $args ) { 640 // Change SVG icon inside social links menu if there is supported URL. 641 if ( 'social' === $args->theme_location ) { 642 $svg = TwentyTwenty_SVG_Icons::get_social_link_svg( $item->url ); 643 if ( empty( $svg ) ) { 644 $svg = twentytwenty_get_theme_svg( 'link' ); 645 } 646 $item_output = str_replace( $args->link_after, '</span>' . $svg, $item_output ); 647 } 648 649 return $item_output; 650 } 651 652 add_filter( 'walker_nav_menu_start_el', 'twentytwenty_nav_menu_social_icons', 10, 4 ); 653 654 /** 655 * Classes 656 */ 657 658 /** 659 * Adds 'no-js' class. 660 * 661 * If we're missing JavaScript support, the HTML element will have a 'no-js' class. 662 * 663 * @since Twenty Twenty 1.0 664 */ 665 function twentytwenty_no_js_class() { 666 $js = "document.documentElement.className = document.documentElement.className.replace( 'no-js', 'js' );"; 667 $js .= "\n//# sourceURL=" . rawurlencode( __FUNCTION__ ); 668 669 if ( function_exists( 'wp_print_inline_script_tag' ) ) { 670 wp_print_inline_script_tag( $js ); 671 } else { 672 echo "<script>$js</script>\n"; 673 } 674 } 675 676 add_action( 'wp_head', 'twentytwenty_no_js_class' ); 677 678 /** 679 * Adds conditional body classes. 680 * 681 * @since Twenty Twenty 1.0 682 * 683 * @global WP_Post $post Global post object. 684 * 685 * @param array $classes Classes added to the body tag. 686 * @return array Classes added to the body tag. 687 */ 688 function twentytwenty_body_classes( $classes ) { 689 690 global $post; 691 $post_type = isset( $post ) ? $post->post_type : false; 692 693 // Check whether we're singular. 694 if ( is_singular() ) { 695 $classes[] = 'singular'; 696 } 697 698 // Check whether the current page should have an overlay header. 699 if ( is_page_template( array( 'templates/template-cover.php' ) ) ) { 700 $classes[] = 'overlay-header'; 701 } 702 703 // Check whether the current page has full-width content. 704 if ( is_page_template( array( 'templates/template-full-width.php' ) ) ) { 705 $classes[] = 'has-full-width-content'; 706 } 707 708 // Check for enabled search. 709 if ( true === get_theme_mod( 'enable_header_search', true ) ) { 710 $classes[] = 'enable-search-modal'; 711 } 712 713 // Check for post thumbnail. 714 if ( is_singular() && has_post_thumbnail() ) { 715 $classes[] = 'has-post-thumbnail'; 716 } elseif ( is_singular() ) { 717 $classes[] = 'missing-post-thumbnail'; 718 } 719 720 // Check whether we're in the customizer preview. 721 if ( is_customize_preview() ) { 722 $classes[] = 'customizer-preview'; 723 } 724 725 // Check if posts have single pagination. 726 if ( is_single() && ( get_next_post() || get_previous_post() ) ) { 727 $classes[] = 'has-single-pagination'; 728 } else { 729 $classes[] = 'has-no-pagination'; 730 } 731 732 // Check if we're showing comments. 733 if ( $post && ( ( 'post' === $post_type || comments_open() || get_comments_number() ) && ! post_password_required() ) ) { 734 $classes[] = 'showing-comments'; 735 } else { 736 $classes[] = 'not-showing-comments'; 737 } 738 739 // Check if avatars are visible. 740 $classes[] = get_option( 'show_avatars' ) ? 'show-avatars' : 'hide-avatars'; 741 742 // Slim page template class names (class = name - file suffix). 743 if ( is_page_template() ) { 744 $classes[] = basename( get_page_template_slug(), '.php' ); 745 } 746 747 // Check for the elements output in the top part of the footer. 748 $has_footer_menu = has_nav_menu( 'footer' ); 749 $has_social_menu = has_nav_menu( 'social' ); 750 $has_sidebar_1 = is_active_sidebar( 'sidebar-1' ); 751 $has_sidebar_2 = is_active_sidebar( 'sidebar-2' ); 752 753 // Add a class indicating whether those elements are output. 754 if ( $has_footer_menu || $has_social_menu || $has_sidebar_1 || $has_sidebar_2 ) { 755 $classes[] = 'footer-top-visible'; 756 } else { 757 $classes[] = 'footer-top-hidden'; 758 } 759 760 // Get header/footer background color. 761 $header_footer_background = get_theme_mod( 'header_footer_background_color', '#ffffff' ); 762 $header_footer_background = strtolower( '#' . ltrim( $header_footer_background, '#' ) ); 763 764 // Get content background color. 765 $background_color = get_theme_mod( 'background_color', 'f5efe0' ); 766 $background_color = strtolower( '#' . ltrim( $background_color, '#' ) ); 767 768 // Add extra class if main background and header/footer background are the same color. 769 if ( $background_color === $header_footer_background ) { 770 $classes[] = 'reduced-spacing'; 771 } 772 773 return $classes; 774 } 775 776 add_filter( 'body_class', 'twentytwenty_body_classes' ); 777 778 /** 779 * Archives 780 */ 781 782 /** 783 * Filters the archive title and styles the word before the first colon. 784 * 785 * @since Twenty Twenty 1.0 786 * 787 * @param string $title Current archive title. 788 * @return string Current archive title. 789 */ 790 function twentytwenty_get_the_archive_title( $title ) { 791 792 /** 793 * Filters the regular expression used to style the word before the first colon. 794 * 795 * @since Twenty Twenty 1.0 796 * 797 * @param array $regex An array of regular expression pattern and replacement. 798 */ 799 $regex = apply_filters( 800 'twentytwenty_get_the_archive_title_regex', 801 array( 802 'pattern' => '/(\A[^\:]+\:)/', 803 'replacement' => '<span class="color-accent">$1</span>', 804 ) 805 ); 806 807 if ( empty( $regex ) ) { 808 809 return $title; 810 811 } 812 813 return preg_replace( $regex['pattern'], $regex['replacement'], $title ); 814 } 815 816 add_filter( 'get_the_archive_title', 'twentytwenty_get_the_archive_title' ); 817 818 /** 819 * Miscellaneous 820 */ 821 822 /** 823 * Toggles animation duration in milliseconds. 824 * 825 * @since Twenty Twenty 1.0 826 * 827 * @return int Duration in milliseconds 828 */ 829 function twentytwenty_toggle_duration() { 830 /** 831 * Filters the animation duration/speed used usually for submenu toggles. 832 * 833 * @since Twenty Twenty 1.0 834 * 835 * @param int $duration Duration in milliseconds. 836 */ 837 $duration = apply_filters( 'twentytwenty_toggle_duration', 250 ); 838 839 return $duration; 840 } 841 842 /** 843 * Gets unique ID. 844 * 845 * This is a PHP implementation of Underscore's uniqueId method. A static variable 846 * contains an integer that is incremented with each call. This number is returned 847 * with the optional prefix. As such the returned value is not universally unique, 848 * but it is unique across the life of the PHP process. 849 * 850 * @since Twenty Twenty 1.0 851 * 852 * @see wp_unique_id() Themes requiring WordPress 5.0.3 and greater should use this instead. 853 * 854 * @param string $prefix Prefix for the returned ID. 855 * @return string Unique ID. 856 */ 857 function twentytwenty_unique_id( $prefix = '' ) { 858 static $id_counter = 0; 859 if ( function_exists( 'wp_unique_id' ) ) { 860 return wp_unique_id( $prefix ); 861 } 862 return $prefix . (string) ++$id_counter; 863 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Wed Nov 11 08:20:02 2026 | Cross-referenced by PHPXref |