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