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