functions.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. <?php
  2. /**
  3. * Remote functions and definitions
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package Remote
  8. * @since Remote 1.0
  9. */
  10. if ( ! function_exists( 'remote_support' ) ) :
  11. /**
  12. * Sets up theme defaults and registers support for various WordPress features.
  13. *
  14. * @since Remote 1.0
  15. *
  16. * @return void
  17. */
  18. function remote_support() {
  19. // Add support for block styles.
  20. add_theme_support( 'wp-block-styles' );
  21. // Enqueue editor styles.
  22. add_editor_style( 'style.css' );
  23. }
  24. endif;
  25. add_action( 'after_setup_theme', 'remote_support' );
  26. if ( ! function_exists( 'remote_styles' ) ) :
  27. /**
  28. * Enqueue styles.
  29. *
  30. * @since Remote 1.0
  31. *
  32. * @return void
  33. */
  34. function remote_styles() {
  35. // Register theme stylesheet.
  36. wp_register_style(
  37. 'remote-style',
  38. get_template_directory_uri() . '/style.css',
  39. array(),
  40. wp_get_theme()->get( 'Version' )
  41. );
  42. // Add styles inline.
  43. wp_add_inline_style( 'remote-style', remote_get_font_face_styles() );
  44. // Enqueue theme stylesheet.
  45. wp_enqueue_style( 'remote-style' );
  46. }
  47. endif;
  48. add_action( 'wp_enqueue_scripts', 'remote_styles' );
  49. if ( ! function_exists( 'remote_editor_styles' ) ) :
  50. /**
  51. * Enqueue editor styles.
  52. *
  53. * @since Remote 1.0
  54. *
  55. * @return void
  56. */
  57. function remote_editor_styles() {
  58. // Add styles inline.
  59. wp_add_inline_style( 'wp-block-library', remote_get_font_face_styles() );
  60. }
  61. endif;
  62. add_action( 'admin_init', 'remote_editor_styles' );
  63. if ( ! function_exists( 'remote_get_font_face_styles' ) ) :
  64. /**
  65. * Get font face styles.
  66. * Called by functions remote_styles() and remote_editor_styles() above.
  67. *
  68. * @since Remote 1.0
  69. *
  70. * @return string
  71. */
  72. function remote_get_font_face_styles() {
  73. return "
  74. @font-face{
  75. font-family: 'DM Sans';
  76. font-weight: 400;
  77. font-style: normal;
  78. font-stretch: normal;
  79. font-display: swap;
  80. src: url('" . get_theme_file_uri( 'assets/fonts/DMSans-Regular.woff2' ) . "') format('woff2');
  81. }
  82. @font-face{
  83. font-family: 'DM Sans';
  84. font-weight: 700;
  85. font-style: normal;
  86. font-stretch: normal;
  87. font-display: swap;
  88. src: url('" . get_theme_file_uri( 'assets/fonts/DMSans-Bold.woff2' ) . "') format('woff2');
  89. }
  90. @font-face{
  91. font-family: 'DM Sans';
  92. font-weight: 400;
  93. font-style: italic;
  94. font-stretch: normal;
  95. font-display: swap;
  96. src: url('" . get_theme_file_uri( 'assets/fonts/DMSans-Italic.woff2' ) . "') format('woff2');
  97. }
  98. @font-face{
  99. font-family: 'DM Sans';
  100. font-weight: 700;
  101. font-style: italic;
  102. font-stretch: normal;
  103. font-display: swap;
  104. src: url('" . get_theme_file_uri( 'assets/fonts/DMSans-BoldItalic.woff2' ) . "') format('woff2');
  105. }
  106. ";
  107. }
  108. endif;
  109. if ( ! function_exists( 'remote_preload_webfonts' ) ) :
  110. /**
  111. * Preloads the main web font to improve performance.
  112. *
  113. * Only the main web font (font-weight: 100,400, font-style: normal) is preloaded here since that font is always relevant.
  114. * The other fonts are only needed if the user changed style or weight of the fonts,
  115. * and therefore preloading it would in most cases regress performance when that font would otherwise not be loaded
  116. * at all.
  117. *
  118. * @since Remote 1.0
  119. *
  120. * @return void
  121. */
  122. function remote_preload_webfonts() {
  123. ?>
  124. <link rel="preload" href="<?php echo esc_url( get_theme_file_uri( 'assets/fonts/DMSans-Regular.woff2' ) ); ?>" as="font" type="font/woff2" crossorigin>
  125. <?php
  126. }
  127. endif;
  128. add_action( 'wp_head', 'remote_preload_webfonts' );
  129. /**
  130. * Block Patterns.
  131. */
  132. require get_template_directory() . '/inc/block-patterns.php';