Geen omschrijving

functions.php 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. /**
  3. * Twenty Twenty-Two functions and definitions
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package WordPress
  8. * @subpackage Twenty_Twenty_Two
  9. * @since Twenty Twenty-Two 1.0
  10. */
  11. if ( ! function_exists( 'twentytwentytwo_support' ) ) :
  12. /**
  13. * Sets up theme defaults and registers support for various WordPress features.
  14. *
  15. * @since Twenty Twenty-Two 1.0
  16. *
  17. * @return void
  18. */
  19. function twentytwentytwo_support() {
  20. // Add support for block styles.
  21. add_theme_support( 'wp-block-styles' );
  22. // Enqueue editor styles.
  23. add_editor_style( 'style.css' );
  24. }
  25. endif;
  26. add_action( 'after_setup_theme', 'twentytwentytwo_support' );
  27. if ( ! function_exists( 'twentytwentytwo_styles' ) ) :
  28. /**
  29. * Enqueue styles.
  30. *
  31. * @since Twenty Twenty-Two 1.0
  32. *
  33. * @return void
  34. */
  35. function twentytwentytwo_styles() {
  36. // Register theme stylesheet.
  37. $theme_version = wp_get_theme()->get( 'Version' );
  38. $version_string = is_string( $theme_version ) ? $theme_version : false;
  39. wp_register_style(
  40. 'twentytwentytwo-style',
  41. get_template_directory_uri() . '/style.css',
  42. array(),
  43. $version_string
  44. );
  45. // Add styles inline.
  46. wp_add_inline_style( 'twentytwentytwo-style', twentytwentytwo_get_font_face_styles() );
  47. // Enqueue theme stylesheet.
  48. wp_enqueue_style( 'twentytwentytwo-style' );
  49. }
  50. endif;
  51. add_action( 'wp_enqueue_scripts', 'twentytwentytwo_styles' );
  52. if ( ! function_exists( 'twentytwentytwo_editor_styles' ) ) :
  53. /**
  54. * Enqueue editor styles.
  55. *
  56. * @since Twenty Twenty-Two 1.0
  57. *
  58. * @return void
  59. */
  60. function twentytwentytwo_editor_styles() {
  61. // Add styles inline.
  62. wp_add_inline_style( 'wp-block-library', twentytwentytwo_get_font_face_styles() );
  63. }
  64. endif;
  65. add_action( 'admin_init', 'twentytwentytwo_editor_styles' );
  66. if ( ! function_exists( 'twentytwentytwo_get_font_face_styles' ) ) :
  67. /**
  68. * Get font face styles.
  69. * Called by functions twentytwentytwo_styles() and twentytwentytwo_editor_styles() above.
  70. *
  71. * @since Twenty Twenty-Two 1.0
  72. *
  73. * @return string
  74. */
  75. function twentytwentytwo_get_font_face_styles() {
  76. return "
  77. @font-face{
  78. font-family: 'Source Serif Pro';
  79. font-weight: 200 900;
  80. font-style: normal;
  81. font-stretch: normal;
  82. font-display: swap;
  83. src: url('" . get_theme_file_uri( 'assets/fonts/SourceSerif4Variable-Roman.ttf.woff2' ) . "') format('woff2');
  84. }
  85. @font-face{
  86. font-family: 'Source Serif Pro';
  87. font-weight: 200 900;
  88. font-style: italic;
  89. font-stretch: normal;
  90. font-display: swap;
  91. src: url('" . get_theme_file_uri( 'assets/fonts/SourceSerif4Variable-Italic.ttf.woff2' ) . "') format('woff2');
  92. }
  93. ";
  94. }
  95. endif;
  96. if ( ! function_exists( 'twentytwentytwo_preload_webfonts' ) ) :
  97. /**
  98. * Preloads the main web font to improve performance.
  99. *
  100. * Only the main web font (font-style: normal) is preloaded here since that font is always relevant (it is used
  101. * on every heading, for example). The other font is only needed if there is any applicable content in italic style,
  102. * and therefore preloading it would in most cases regress performance when that font would otherwise not be loaded
  103. * at all.
  104. *
  105. * @since Twenty Twenty-Two 1.0
  106. *
  107. * @return void
  108. */
  109. function twentytwentytwo_preload_webfonts() {
  110. ?>
  111. <link rel="preload" href="<?php echo esc_url( get_theme_file_uri( 'assets/fonts/SourceSerif4Variable-Roman.ttf.woff2' ) ); ?>" as="font" type="font/woff2" crossorigin>
  112. <?php
  113. }
  114. endif;
  115. add_action( 'wp_head', 'twentytwentytwo_preload_webfonts' );
  116. // Add block patterns
  117. require get_template_directory() . '/inc/block-patterns.php';