functions.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. <?php
  2. /**
  3. * Twenty Seventeen functions and definitions
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package WordPress
  8. * @subpackage Twenty_Seventeen
  9. * @since 1.0
  10. */
  11. /**
  12. * Twenty Seventeen only works in WordPress 4.7 or later.
  13. */
  14. if ( version_compare( $GLOBALS['wp_version'], '4.7-alpha', '<' ) ) {
  15. require get_template_directory() . '/inc/back-compat.php';
  16. return;
  17. }
  18. /**
  19. * Sets up theme defaults and registers support for various WordPress features.
  20. *
  21. * Note that this function is hooked into the after_setup_theme hook, which
  22. * runs before the init hook. The init hook is too late for some features, such
  23. * as indicating support for post thumbnails.
  24. */
  25. function twentyseventeen_setup() {
  26. /*
  27. * Make theme available for translation.
  28. * Translations can be filed at WordPress.org. See: https://translate.wordpress.org/projects/wp-themes/twentyseventeen
  29. * If you're building a theme based on Twenty Seventeen, use a find and replace
  30. * to change 'twentyseventeen' to the name of your theme in all the template files.
  31. */
  32. load_theme_textdomain( 'twentyseventeen' );
  33. // Add default posts and comments RSS feed links to head.
  34. add_theme_support( 'automatic-feed-links' );
  35. /*
  36. * Let WordPress manage the document title.
  37. * By adding theme support, we declare that this theme does not use a
  38. * hard-coded <title> tag in the document head, and expect WordPress to
  39. * provide it for us.
  40. */
  41. add_theme_support( 'title-tag' );
  42. /*
  43. * Enable support for Post Thumbnails on posts and pages.
  44. *
  45. * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  46. */
  47. add_theme_support( 'post-thumbnails' );
  48. add_image_size( 'twentyseventeen-featured-image', 2000, 1200, true );
  49. add_image_size( 'twentyseventeen-thumbnail-avatar', 100, 100, true );
  50. // Set the default content width.
  51. $GLOBALS['content_width'] = 525;
  52. // This theme uses wp_nav_menu() in two locations.
  53. register_nav_menus(
  54. array(
  55. 'top' => __( 'Top Menu', 'twentyseventeen' ),
  56. 'social' => __( 'Social Links Menu', 'twentyseventeen' ),
  57. )
  58. );
  59. /*
  60. * Switch default core markup for search form, comment form, and comments
  61. * to output valid HTML5.
  62. */
  63. add_theme_support(
  64. 'html5',
  65. array(
  66. 'comment-form',
  67. 'comment-list',
  68. 'gallery',
  69. 'caption',
  70. 'script',
  71. 'style',
  72. )
  73. );
  74. /*
  75. * Enable support for Post Formats.
  76. *
  77. * See: https://wordpress.org/support/article/post-formats/
  78. */
  79. add_theme_support(
  80. 'post-formats',
  81. array(
  82. 'aside',
  83. 'image',
  84. 'video',
  85. 'quote',
  86. 'link',
  87. 'gallery',
  88. 'audio',
  89. )
  90. );
  91. // Add theme support for Custom Logo.
  92. add_theme_support(
  93. 'custom-logo',
  94. array(
  95. 'width' => 250,
  96. 'height' => 250,
  97. 'flex-width' => true,
  98. )
  99. );
  100. // Add theme support for selective refresh for widgets.
  101. add_theme_support( 'customize-selective-refresh-widgets' );
  102. /*
  103. * This theme styles the visual editor to resemble the theme style,
  104. * specifically font, colors, and column width.
  105. */
  106. add_editor_style( array( 'assets/css/editor-style.css', twentyseventeen_fonts_url() ) );
  107. // Load regular editor styles into the new block-based editor.
  108. add_theme_support( 'editor-styles' );
  109. // Load default block styles.
  110. add_theme_support( 'wp-block-styles' );
  111. // Add support for responsive embeds.
  112. add_theme_support( 'responsive-embeds' );
  113. // Define and register starter content to showcase the theme on new sites.
  114. $starter_content = array(
  115. 'widgets' => array(
  116. // Place three core-defined widgets in the sidebar area.
  117. 'sidebar-1' => array(
  118. 'text_business_info',
  119. 'search',
  120. 'text_about',
  121. ),
  122. // Add the core-defined business info widget to the footer 1 area.
  123. 'sidebar-2' => array(
  124. 'text_business_info',
  125. ),
  126. // Put two core-defined widgets in the footer 2 area.
  127. 'sidebar-3' => array(
  128. 'text_about',
  129. 'search',
  130. ),
  131. ),
  132. // Specify the core-defined pages to create and add custom thumbnails to some of them.
  133. 'posts' => array(
  134. 'home',
  135. 'about' => array(
  136. 'thumbnail' => '{{image-sandwich}}',
  137. ),
  138. 'contact' => array(
  139. 'thumbnail' => '{{image-espresso}}',
  140. ),
  141. 'blog' => array(
  142. 'thumbnail' => '{{image-coffee}}',
  143. ),
  144. 'homepage-section' => array(
  145. 'thumbnail' => '{{image-espresso}}',
  146. ),
  147. ),
  148. // Create the custom image attachments used as post thumbnails for pages.
  149. 'attachments' => array(
  150. 'image-espresso' => array(
  151. 'post_title' => _x( 'Espresso', 'Theme starter content', 'twentyseventeen' ),
  152. 'file' => 'assets/images/espresso.jpg', // URL relative to the template directory.
  153. ),
  154. 'image-sandwich' => array(
  155. 'post_title' => _x( 'Sandwich', 'Theme starter content', 'twentyseventeen' ),
  156. 'file' => 'assets/images/sandwich.jpg',
  157. ),
  158. 'image-coffee' => array(
  159. 'post_title' => _x( 'Coffee', 'Theme starter content', 'twentyseventeen' ),
  160. 'file' => 'assets/images/coffee.jpg',
  161. ),
  162. ),
  163. // Default to a static front page and assign the front and posts pages.
  164. 'options' => array(
  165. 'show_on_front' => 'page',
  166. 'page_on_front' => '{{home}}',
  167. 'page_for_posts' => '{{blog}}',
  168. ),
  169. // Set the front page section theme mods to the IDs of the core-registered pages.
  170. 'theme_mods' => array(
  171. 'panel_1' => '{{homepage-section}}',
  172. 'panel_2' => '{{about}}',
  173. 'panel_3' => '{{blog}}',
  174. 'panel_4' => '{{contact}}',
  175. ),
  176. // Set up nav menus for each of the two areas registered in the theme.
  177. 'nav_menus' => array(
  178. // Assign a menu to the "top" location.
  179. 'top' => array(
  180. 'name' => __( 'Top Menu', 'twentyseventeen' ),
  181. 'items' => array(
  182. 'link_home', // Note that the core "home" page is actually a link in case a static front page is not used.
  183. 'page_about',
  184. 'page_blog',
  185. 'page_contact',
  186. ),
  187. ),
  188. // Assign a menu to the "social" location.
  189. 'social' => array(
  190. 'name' => __( 'Social Links Menu', 'twentyseventeen' ),
  191. 'items' => array(
  192. 'link_yelp',
  193. 'link_facebook',
  194. 'link_twitter',
  195. 'link_instagram',
  196. 'link_email',
  197. ),
  198. ),
  199. ),
  200. );
  201. /**
  202. * Filters Twenty Seventeen array of starter content.
  203. *
  204. * @since Twenty Seventeen 1.1
  205. *
  206. * @param array $starter_content Array of starter content.
  207. */
  208. $starter_content = apply_filters( 'twentyseventeen_starter_content', $starter_content );
  209. add_theme_support( 'starter-content', $starter_content );
  210. }
  211. add_action( 'after_setup_theme', 'twentyseventeen_setup' );
  212. /**
  213. * Set the content width in pixels, based on the theme's design and stylesheet.
  214. *
  215. * Priority 0 to make it available to lower priority callbacks.
  216. *
  217. * @global int $content_width
  218. */
  219. function twentyseventeen_content_width() {
  220. $content_width = $GLOBALS['content_width'];
  221. // Get layout.
  222. $page_layout = get_theme_mod( 'page_layout' );
  223. // Check if layout is one column.
  224. if ( 'one-column' === $page_layout ) {
  225. if ( twentyseventeen_is_frontpage() ) {
  226. $content_width = 644;
  227. } elseif ( is_page() ) {
  228. $content_width = 740;
  229. }
  230. }
  231. // Check if is single post and there is no sidebar.
  232. if ( is_single() && ! is_active_sidebar( 'sidebar-1' ) ) {
  233. $content_width = 740;
  234. }
  235. /**
  236. * Filter Twenty Seventeen content width of the theme.
  237. *
  238. * @since Twenty Seventeen 1.0
  239. *
  240. * @param int $content_width Content width in pixels.
  241. */
  242. $GLOBALS['content_width'] = apply_filters( 'twentyseventeen_content_width', $content_width );
  243. }
  244. add_action( 'template_redirect', 'twentyseventeen_content_width', 0 );
  245. /**
  246. * Register custom fonts.
  247. */
  248. function twentyseventeen_fonts_url() {
  249. $fonts_url = '';
  250. /*
  251. * translators: If there are characters in your language that are not supported
  252. * by Libre Franklin, translate this to 'off'. Do not translate into your own language.
  253. */
  254. $libre_franklin = _x( 'on', 'Libre Franklin font: on or off', 'twentyseventeen' );
  255. if ( 'off' !== $libre_franklin ) {
  256. $font_families = array();
  257. $font_families[] = 'Libre Franklin:300,300i,400,400i,600,600i,800,800i';
  258. $query_args = array(
  259. 'family' => urlencode( implode( '|', $font_families ) ),
  260. 'subset' => urlencode( 'latin,latin-ext' ),
  261. 'display' => urlencode( 'fallback' ),
  262. );
  263. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  264. }
  265. return esc_url_raw( $fonts_url );
  266. }
  267. /**
  268. * Add preconnect for Google Fonts.
  269. *
  270. * @since Twenty Seventeen 1.0
  271. *
  272. * @param array $urls URLs to print for resource hints.
  273. * @param string $relation_type The relation type the URLs are printed.
  274. * @return array $urls URLs to print for resource hints.
  275. */
  276. function twentyseventeen_resource_hints( $urls, $relation_type ) {
  277. if ( wp_style_is( 'twentyseventeen-fonts', 'queue' ) && 'preconnect' === $relation_type ) {
  278. $urls[] = array(
  279. 'href' => 'https://fonts.gstatic.com',
  280. 'crossorigin',
  281. );
  282. }
  283. return $urls;
  284. }
  285. add_filter( 'wp_resource_hints', 'twentyseventeen_resource_hints', 10, 2 );
  286. /**
  287. * Register widget area.
  288. *
  289. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  290. */
  291. function twentyseventeen_widgets_init() {
  292. register_sidebar(
  293. array(
  294. 'name' => __( 'Blog Sidebar', 'twentyseventeen' ),
  295. 'id' => 'sidebar-1',
  296. 'description' => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'twentyseventeen' ),
  297. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  298. 'after_widget' => '</section>',
  299. 'before_title' => '<h2 class="widget-title">',
  300. 'after_title' => '</h2>',
  301. )
  302. );
  303. register_sidebar(
  304. array(
  305. 'name' => __( 'Footer 1', 'twentyseventeen' ),
  306. 'id' => 'sidebar-2',
  307. 'description' => __( 'Add widgets here to appear in your footer.', 'twentyseventeen' ),
  308. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  309. 'after_widget' => '</section>',
  310. 'before_title' => '<h2 class="widget-title">',
  311. 'after_title' => '</h2>',
  312. )
  313. );
  314. register_sidebar(
  315. array(
  316. 'name' => __( 'Footer 2', 'twentyseventeen' ),
  317. 'id' => 'sidebar-3',
  318. 'description' => __( 'Add widgets here to appear in your footer.', 'twentyseventeen' ),
  319. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  320. 'after_widget' => '</section>',
  321. 'before_title' => '<h2 class="widget-title">',
  322. 'after_title' => '</h2>',
  323. )
  324. );
  325. }
  326. add_action( 'widgets_init', 'twentyseventeen_widgets_init' );
  327. /**
  328. * Replaces "[...]" (appended to automatically generated excerpts) with ... and
  329. * a 'Continue reading' link.
  330. *
  331. * @since Twenty Seventeen 1.0
  332. *
  333. * @param string $link Link to single post/page.
  334. * @return string 'Continue reading' link prepended with an ellipsis.
  335. */
  336. function twentyseventeen_excerpt_more( $link ) {
  337. if ( is_admin() ) {
  338. return $link;
  339. }
  340. $link = sprintf(
  341. '<p class="link-more"><a href="%1$s" class="more-link">%2$s</a></p>',
  342. esc_url( get_permalink( get_the_ID() ) ),
  343. /* translators: %s: Post title. */
  344. sprintf( __( 'Continue reading<span class="screen-reader-text"> "%s"</span>', 'twentyseventeen' ), get_the_title( get_the_ID() ) )
  345. );
  346. return ' &hellip; ' . $link;
  347. }
  348. add_filter( 'excerpt_more', 'twentyseventeen_excerpt_more' );
  349. /**
  350. * Handles JavaScript detection.
  351. *
  352. * Adds a `js` class to the root `<html>` element when JavaScript is detected.
  353. *
  354. * @since Twenty Seventeen 1.0
  355. */
  356. function twentyseventeen_javascript_detection() {
  357. echo "<script>(function(html){html.className = html.className.replace(/\bno-js\b/,'js')})(document.documentElement);</script>\n";
  358. }
  359. add_action( 'wp_head', 'twentyseventeen_javascript_detection', 0 );
  360. /**
  361. * Add a pingback url auto-discovery header for singularly identifiable articles.
  362. */
  363. function twentyseventeen_pingback_header() {
  364. if ( is_singular() && pings_open() ) {
  365. printf( '<link rel="pingback" href="%s">' . "\n", esc_url( get_bloginfo( 'pingback_url' ) ) );
  366. }
  367. }
  368. add_action( 'wp_head', 'twentyseventeen_pingback_header' );
  369. /**
  370. * Display custom color CSS.
  371. */
  372. function twentyseventeen_colors_css_wrap() {
  373. if ( 'custom' !== get_theme_mod( 'colorscheme' ) && ! is_customize_preview() ) {
  374. return;
  375. }
  376. require_once( get_parent_theme_file_path( '/inc/color-patterns.php' ) );
  377. $hue = absint( get_theme_mod( 'colorscheme_hue', 250 ) );
  378. $customize_preview_data_hue = '';
  379. if ( is_customize_preview() ) {
  380. $customize_preview_data_hue = 'data-hue="' . $hue . '"';
  381. }
  382. ?>
  383. <style type="text/css" id="custom-theme-colors" <?php echo $customize_preview_data_hue; ?>>
  384. <?php echo twentyseventeen_custom_colors_css(); ?>
  385. </style>
  386. <?php
  387. }
  388. add_action( 'wp_head', 'twentyseventeen_colors_css_wrap' );
  389. /**
  390. * Enqueues scripts and styles.
  391. */
  392. function twentyseventeen_scripts() {
  393. // Add custom fonts, used in the main stylesheet.
  394. wp_enqueue_style( 'twentyseventeen-fonts', twentyseventeen_fonts_url(), array(), null );
  395. // Theme stylesheet.
  396. wp_enqueue_style( 'twentyseventeen-style', get_stylesheet_uri(), array(), '20190507' );
  397. // Theme block stylesheet.
  398. wp_enqueue_style( 'twentyseventeen-block-style', get_theme_file_uri( '/assets/css/blocks.css' ), array( 'twentyseventeen-style' ), '20190105' );
  399. // Load the dark colorscheme.
  400. if ( 'dark' === get_theme_mod( 'colorscheme', 'light' ) || is_customize_preview() ) {
  401. wp_enqueue_style( 'twentyseventeen-colors-dark', get_theme_file_uri( '/assets/css/colors-dark.css' ), array( 'twentyseventeen-style' ), '20190408' );
  402. }
  403. // Load the Internet Explorer 9 specific stylesheet, to fix display issues in the Customizer.
  404. if ( is_customize_preview() ) {
  405. wp_enqueue_style( 'twentyseventeen-ie9', get_theme_file_uri( '/assets/css/ie9.css' ), array( 'twentyseventeen-style' ), '20161202' );
  406. wp_style_add_data( 'twentyseventeen-ie9', 'conditional', 'IE 9' );
  407. }
  408. // Load the Internet Explorer 8 specific stylesheet.
  409. wp_enqueue_style( 'twentyseventeen-ie8', get_theme_file_uri( '/assets/css/ie8.css' ), array( 'twentyseventeen-style' ), '20161202' );
  410. wp_style_add_data( 'twentyseventeen-ie8', 'conditional', 'lt IE 9' );
  411. // Load the html5 shiv.
  412. wp_enqueue_script( 'html5', get_theme_file_uri( '/assets/js/html5.js' ), array(), '20161020' );
  413. wp_script_add_data( 'html5', 'conditional', 'lt IE 9' );
  414. wp_enqueue_script( 'twentyseventeen-skip-link-focus-fix', get_theme_file_uri( '/assets/js/skip-link-focus-fix.js' ), array(), '20161114', true );
  415. $twentyseventeen_l10n = array(
  416. 'quote' => twentyseventeen_get_svg( array( 'icon' => 'quote-right' ) ),
  417. );
  418. if ( has_nav_menu( 'top' ) ) {
  419. wp_enqueue_script( 'twentyseventeen-navigation', get_theme_file_uri( '/assets/js/navigation.js' ), array( 'jquery' ), '20161203', true );
  420. $twentyseventeen_l10n['expand'] = __( 'Expand child menu', 'twentyseventeen' );
  421. $twentyseventeen_l10n['collapse'] = __( 'Collapse child menu', 'twentyseventeen' );
  422. $twentyseventeen_l10n['icon'] = twentyseventeen_get_svg(
  423. array(
  424. 'icon' => 'angle-down',
  425. 'fallback' => true,
  426. )
  427. );
  428. }
  429. wp_enqueue_script( 'twentyseventeen-global', get_theme_file_uri( '/assets/js/global.js' ), array( 'jquery' ), '20190121', true );
  430. wp_enqueue_script( 'jquery-scrollto', get_theme_file_uri( '/assets/js/jquery.scrollTo.js' ), array( 'jquery' ), '2.1.2', true );
  431. wp_localize_script( 'twentyseventeen-skip-link-focus-fix', 'twentyseventeenScreenReaderText', $twentyseventeen_l10n );
  432. if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
  433. wp_enqueue_script( 'comment-reply' );
  434. }
  435. }
  436. add_action( 'wp_enqueue_scripts', 'twentyseventeen_scripts' );
  437. /**
  438. * Enqueues styles for the block-based editor.
  439. *
  440. * @since Twenty Seventeen 1.8
  441. */
  442. function twentyseventeen_block_editor_styles() {
  443. // Block styles.
  444. wp_enqueue_style( 'twentyseventeen-block-editor-style', get_theme_file_uri( '/assets/css/editor-blocks.css' ), array(), '20190328' );
  445. // Add custom fonts.
  446. wp_enqueue_style( 'twentyseventeen-fonts', twentyseventeen_fonts_url(), array(), null );
  447. }
  448. add_action( 'enqueue_block_editor_assets', 'twentyseventeen_block_editor_styles' );
  449. /**
  450. * Add custom image sizes attribute to enhance responsive image functionality
  451. * for content images.
  452. *
  453. * @since Twenty Seventeen 1.0
  454. *
  455. * @param string $sizes A source size value for use in a 'sizes' attribute.
  456. * @param array $size Image size. Accepts an array of width and height
  457. * values in pixels (in that order).
  458. * @return string A source size value for use in a content image 'sizes' attribute.
  459. */
  460. function twentyseventeen_content_image_sizes_attr( $sizes, $size ) {
  461. $width = $size[0];
  462. if ( 740 <= $width ) {
  463. $sizes = '(max-width: 706px) 89vw, (max-width: 767px) 82vw, 740px';
  464. }
  465. if ( is_active_sidebar( 'sidebar-1' ) || is_archive() || is_search() || is_home() || is_page() ) {
  466. if ( ! ( is_page() && 'one-column' === get_theme_mod( 'page_options' ) ) && 767 <= $width ) {
  467. $sizes = '(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px';
  468. }
  469. }
  470. return $sizes;
  471. }
  472. add_filter( 'wp_calculate_image_sizes', 'twentyseventeen_content_image_sizes_attr', 10, 2 );
  473. /**
  474. * Filter the `sizes` value in the header image markup.
  475. *
  476. * @since Twenty Seventeen 1.0
  477. *
  478. * @param string $html The HTML image tag markup being filtered.
  479. * @param object $header The custom header object returned by 'get_custom_header()'.
  480. * @param array $attr Array of the attributes for the image tag.
  481. * @return string The filtered header image HTML.
  482. */
  483. function twentyseventeen_header_image_tag( $html, $header, $attr ) {
  484. if ( isset( $attr['sizes'] ) ) {
  485. $html = str_replace( $attr['sizes'], '100vw', $html );
  486. }
  487. return $html;
  488. }
  489. add_filter( 'get_header_image_tag', 'twentyseventeen_header_image_tag', 10, 3 );
  490. /**
  491. * Add custom image sizes attribute to enhance responsive image functionality
  492. * for post thumbnails.
  493. *
  494. * @since Twenty Seventeen 1.0
  495. *
  496. * @param array $attr Attributes for the image markup.
  497. * @param int $attachment Image attachment ID.
  498. * @param array $size Registered image size or flat array of height and width dimensions.
  499. * @return array The filtered attributes for the image markup.
  500. */
  501. function twentyseventeen_post_thumbnail_sizes_attr( $attr, $attachment, $size ) {
  502. if ( is_archive() || is_search() || is_home() ) {
  503. $attr['sizes'] = '(max-width: 767px) 89vw, (max-width: 1000px) 54vw, (max-width: 1071px) 543px, 580px';
  504. } else {
  505. $attr['sizes'] = '100vw';
  506. }
  507. return $attr;
  508. }
  509. add_filter( 'wp_get_attachment_image_attributes', 'twentyseventeen_post_thumbnail_sizes_attr', 10, 3 );
  510. /**
  511. * Use front-page.php when Front page displays is set to a static page.
  512. *
  513. * @since Twenty Seventeen 1.0
  514. *
  515. * @param string $template front-page.php.
  516. *
  517. * @return string The template to be used: blank if is_home() is true (defaults to index.php), else $template.
  518. */
  519. function twentyseventeen_front_page_template( $template ) {
  520. return is_home() ? '' : $template;
  521. }
  522. add_filter( 'frontpage_template', 'twentyseventeen_front_page_template' );
  523. /**
  524. * Modifies tag cloud widget arguments to display all tags in the same font size
  525. * and use list format for better accessibility.
  526. *
  527. * @since Twenty Seventeen 1.4
  528. *
  529. * @param array $args Arguments for tag cloud widget.
  530. * @return array The filtered arguments for tag cloud widget.
  531. */
  532. function twentyseventeen_widget_tag_cloud_args( $args ) {
  533. $args['largest'] = 1;
  534. $args['smallest'] = 1;
  535. $args['unit'] = 'em';
  536. $args['format'] = 'list';
  537. return $args;
  538. }
  539. add_filter( 'widget_tag_cloud_args', 'twentyseventeen_widget_tag_cloud_args' );
  540. /**
  541. * Get unique ID.
  542. *
  543. * This is a PHP implementation of Underscore's uniqueId method. A static variable
  544. * contains an integer that is incremented with each call. This number is returned
  545. * with the optional prefix. As such the returned value is not universally unique,
  546. * but it is unique across the life of the PHP process.
  547. *
  548. * @since Twenty Seventeen 2.0
  549. * @see wp_unique_id() Themes requiring WordPress 5.0.3 and greater should use this instead.
  550. *
  551. * @staticvar int $id_counter
  552. *
  553. * @param string $prefix Prefix for the returned ID.
  554. * @return string Unique ID.
  555. */
  556. function twentyseventeen_unique_id( $prefix = '' ) {
  557. static $id_counter = 0;
  558. if ( function_exists( 'wp_unique_id' ) ) {
  559. return wp_unique_id( $prefix );
  560. }
  561. return $prefix . (string) ++$id_counter;
  562. }
  563. /**
  564. * Implement the Custom Header feature.
  565. */
  566. require get_parent_theme_file_path( '/inc/custom-header.php' );
  567. /**
  568. * Custom template tags for this theme.
  569. */
  570. require get_parent_theme_file_path( '/inc/template-tags.php' );
  571. /**
  572. * Additional features to allow styling of the templates.
  573. */
  574. require get_parent_theme_file_path( '/inc/template-functions.php' );
  575. /**
  576. * Customizer additions.
  577. */
  578. require get_parent_theme_file_path( '/inc/customizer.php' );
  579. /**
  580. * SVG icons functions and filters.
  581. */
  582. require get_parent_theme_file_path( '/inc/icon-functions.php' );