PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/wp-content/themes/twentytwenty/inc/template-tags.php

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