functions.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. <?php
  2. /**
  3. * Skatepark functions and definitions
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package Skatepark
  8. * @since Skatepark 1.0
  9. */
  10. /**
  11. * Add class to body if post/page has a featured image.
  12. */
  13. function skatepark_add_featured_image_class( $classes ) {
  14. global $post;
  15. if ( isset( $post->ID ) && get_the_post_thumbnail( $post->ID ) ) {
  16. $classes[] = 'has-featured-image';
  17. }
  18. return $classes;
  19. }
  20. add_filter( 'body_class', 'skatepark_add_featured_image_class' );
  21. if ( ! function_exists( 'skatepark_support' ) ) :
  22. /**
  23. * Sets up theme defaults and registers support for various WordPress features.
  24. *
  25. * @since Skatepark 1.0
  26. *
  27. * @return void
  28. */
  29. function skatepark_support() {
  30. // Make theme available for translation.
  31. load_theme_textdomain( 'skatepark' );
  32. // Add support for block styles.
  33. add_theme_support( 'wp-block-styles' );
  34. // Enqueue editor styles.
  35. add_editor_style( 'style.css' );
  36. }
  37. endif;
  38. add_action( 'after_setup_theme', 'skatepark_support' );
  39. if ( ! function_exists( 'skatepark_styles' ) ) :
  40. /**
  41. * Enqueue styles.
  42. *
  43. * @since Skatepark 1.0
  44. *
  45. * @return void
  46. */
  47. function skatepark_styles() {
  48. // Register theme stylesheet.
  49. wp_register_style(
  50. 'skatepark-style',
  51. get_template_directory_uri() . '/assets/theme.css',
  52. array(),
  53. wp_get_theme()->get( 'Version' )
  54. );
  55. // Add styles inline.
  56. wp_add_inline_style( 'skatepark-style', skatepark_get_font_face_styles() );
  57. // Enqueue theme stylesheet.
  58. wp_enqueue_style( 'skatepark-style' );
  59. }
  60. endif;
  61. add_action( 'wp_enqueue_scripts', 'skatepark_styles' );
  62. if ( ! function_exists( 'skatepark_editor_styles' ) ) :
  63. /**
  64. * Enqueue editor styles.
  65. *
  66. * @since Skatepark 1.0
  67. *
  68. * @return void
  69. */
  70. function skatepark_editor_styles() {
  71. // Add styles inline.
  72. wp_add_inline_style( 'wp-block-library', skatepark_get_font_face_styles() );
  73. add_editor_style(
  74. get_template_directory_uri() . '/assets/theme.css'
  75. );
  76. }
  77. endif;
  78. add_action( 'admin_init', 'skatepark_editor_styles' );
  79. if ( ! function_exists( 'skatepark_get_font_face_styles' ) ) :
  80. /**
  81. * Get font face styles.
  82. * Called by functions skatepark_styles() and skatepark_editor_styles() above.
  83. *
  84. * @since Skatepark 1.0
  85. *
  86. * @return string
  87. */
  88. function skatepark_get_font_face_styles() {
  89. return "
  90. @font-face{
  91. font-family: 'Red Hat Display';
  92. font-weight: 400;
  93. font-style: normal;
  94. font-stretch: normal;
  95. font-display: swap;
  96. src: url('" . get_theme_file_uri( 'assets/fonts/red-hat-display-regular.woff2' ) . "') format('woff2');
  97. }
  98. @font-face{
  99. font-family: 'Red Hat Display';
  100. font-weight: 500;
  101. font-style: normal;
  102. font-stretch: normal;
  103. font-display: swap;
  104. src: url('" . get_theme_file_uri( 'assets/fonts/red-hat-display-500.woff2' ) . "') format('woff2');
  105. }
  106. @font-face{
  107. font-family: 'Red Hat Display';
  108. font-weight: 700;
  109. font-style: normal;
  110. font-stretch: normal;
  111. font-display: swap;
  112. src: url('" . get_theme_file_uri( 'assets/fonts/red-hat-display-700.woff2' ) . "') format('woff2');
  113. }
  114. @font-face{
  115. font-family: 'Red Hat Display';
  116. font-weight: 900;
  117. font-style: normal;
  118. font-stretch: normal;
  119. font-display: swap;
  120. src: url('" . get_theme_file_uri( 'assets/fonts/red-hat-display-900.woff2' ) . "') format('woff2');
  121. }
  122. @font-face{
  123. font-family: 'Red Hat Display';
  124. font-weight: 400;
  125. font-style: italic;
  126. font-stretch: normal;
  127. font-display: swap;
  128. src: url('" . get_theme_file_uri( 'assets/fonts/red-hat-display-italic.woff2' ) . "') format('woff2');
  129. }
  130. @font-face{
  131. font-family: 'Red Hat Display';
  132. font-weight: 500;
  133. font-style: italic;
  134. font-stretch: normal;
  135. font-display: swap;
  136. src: url('" . get_theme_file_uri( 'assets/fonts/red-hat-display-500italic.woff2' ) . "') format('woff2');
  137. }
  138. @font-face{
  139. font-family: 'Red Hat Display';
  140. font-weight: 700;
  141. font-style: italic;
  142. font-stretch: normal;
  143. font-display: swap;
  144. src: url('" . get_theme_file_uri( 'assets/fonts/red-hat-display-700italic.woff2' ) . "') format('woff2');
  145. }
  146. @font-face{
  147. font-family: 'Red Hat Display';
  148. font-weight: 900;
  149. font-style: italic;
  150. font-stretch: normal;
  151. font-display: swap;
  152. src: url('" . get_theme_file_uri( 'assets/fonts/red-hat-display-900italic.woff2' ) . "') format('woff2');
  153. }
  154. ";
  155. }
  156. endif;
  157. if ( ! function_exists( 'skatepark_preload_webfonts' ) ) :
  158. /**
  159. * Preloads the main web font to improve performance.
  160. *
  161. * Only the main web font (font-weight: 400,700, font-style: normal) is preloaded here since that font is always relevant.
  162. * The other fonts are only needed if the user changed style or weight of the fonts,
  163. * and therefore preloading it would in most cases regress performance when that font would otherwise not be loaded
  164. * at all.
  165. *
  166. * @since Skatepark 1.0
  167. *
  168. * @return void
  169. */
  170. function skatepark_preload_webfonts() {
  171. ?>
  172. <link rel="preload" href="<?php echo esc_url( get_theme_file_uri( 'assets/fonts/red-hat-display-regular.woff2' ) ); ?>" as="font" type="font/woff2" crossorigin>
  173. <link rel="preload" href="<?php echo esc_url( get_theme_file_uri( 'assets/fonts/red-hat-display-700.woff2' ) ); ?>" as="font" type="font/woff2" crossorigin>
  174. <?php
  175. }
  176. endif;
  177. add_action( 'wp_head', 'skatepark_preload_webfonts' );
  178. /**
  179. * Registers block patterns and categories.
  180. *
  181. * @since Skatepark 1.0
  182. *
  183. * @return void
  184. */
  185. function skatepark_register_block_pattern_categories() {
  186. //Needed until https://github.com/WordPress/gutenberg/issues/39500 is fixed.
  187. $block_pattern_categories = array(
  188. 'featured' => array( 'label' => __( 'Featured', 'skatepark' ) ),
  189. 'columns' => array( 'label' => __( 'Columns', 'skatepark' ) ),
  190. 'images' => array( 'label' => __( 'Images', 'skatepark' ) ),
  191. 'text' => array( 'label' => __( 'Text', 'skatepark' ) ),
  192. 'query' => array( 'label' => __( 'Query', 'skatepark' ) ),
  193. );
  194. /**
  195. * Filters the theme block pattern categories.
  196. *
  197. * @since Skatepark 1.0
  198. *
  199. * @param array[] $block_pattern_categories {
  200. * An associative array of block pattern categories, keyed by category name.
  201. *
  202. * @type array[] $properties {
  203. * An array of block category properties.
  204. *
  205. * @type string $label A human-readable label for the pattern category.
  206. * }
  207. * }
  208. */
  209. $block_pattern_categories = apply_filters( 'skatepark_block_pattern_categories', $block_pattern_categories );
  210. foreach ( $block_pattern_categories as $name => $properties ) {
  211. if ( ! WP_Block_Pattern_Categories_Registry::get_instance()->is_registered( $name ) ) {
  212. register_block_pattern_category( $name, $properties );
  213. }
  214. }
  215. }
  216. add_action( 'init', 'skatepark_register_block_pattern_categories', 9 );