functions.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. /**
  3. * Child Theme Functions and definitions
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package WordPress
  8. * @subpackage Shawburn
  9. * @since 1.0.0
  10. */
  11. if ( ! function_exists( 'shawburn_setup' ) ) :
  12. /**
  13. * Sets up theme defaults and registers support for various WordPress features.
  14. *
  15. * Note that this function is hooked into the after_setup_theme hook, which
  16. * runs before the init hook. The init hook is too late for some features, such
  17. * as indicating support for post thumbnails.
  18. */
  19. function shawburn_setup() {
  20. // Add child theme editor styles, compiled from `style-child-theme-editor.scss`.
  21. add_editor_style( 'style-editor.css' );
  22. // Add child theme editor font sizes to match Sass-map variables in `_config-child-theme-deep.scss`.
  23. add_theme_support(
  24. 'editor-font-sizes',
  25. array(
  26. array(
  27. 'name' => __( 'Small', 'shawburn' ),
  28. 'shortName' => __( 'S', 'shawburn' ),
  29. 'size' => 15,
  30. 'slug' => 'small',
  31. ),
  32. array(
  33. 'name' => __( 'Normal', 'shawburn' ),
  34. 'shortName' => __( 'M', 'shawburn' ),
  35. 'size' => 18,
  36. 'slug' => 'normal',
  37. ),
  38. array(
  39. 'name' => __( 'Large', 'shawburn' ),
  40. 'shortName' => __( 'L', 'shawburn' ),
  41. 'size' => 25.92,
  42. 'slug' => 'large',
  43. ),
  44. array(
  45. 'name' => __( 'Huge', 'shawburn' ),
  46. 'shortName' => __( 'XL', 'shawburn' ),
  47. 'size' => 31.104,
  48. 'slug' => 'huge',
  49. ),
  50. )
  51. );
  52. // Add child theme editor color pallete to match Sass-map variables in `_config-child-theme-deep.scss`.
  53. add_theme_support(
  54. 'editor-color-palette',
  55. array(
  56. array(
  57. 'name' => __( 'Primary', 'shawburn' ),
  58. 'slug' => 'primary',
  59. 'color' => '#0C80A1',
  60. ),
  61. array(
  62. 'name' => __( 'Secondary', 'shawburn' ),
  63. 'slug' => 'secondary',
  64. 'color' => '#D4401C',
  65. ),
  66. array(
  67. 'name' => __( 'Dark Gray', 'shawburn' ),
  68. 'slug' => 'foreground-dark',
  69. 'color' => '#222222',
  70. ),
  71. array(
  72. 'name' => __( 'Gray', 'shawburn' ),
  73. 'slug' => 'foreground',
  74. 'color' => '#444444',
  75. ),
  76. array(
  77. 'name' => __( 'Light Gray', 'shawburn' ),
  78. 'slug' => 'foreground-light',
  79. 'color' => '#767676',
  80. ),
  81. array(
  82. 'name' => __( 'Light Gray', 'shawburn' ),
  83. 'slug' => 'background-dark',
  84. 'color' => '#EAEAEA',
  85. ),
  86. array(
  87. 'name' => __( 'Subtle Gray', 'shawburn' ),
  88. 'slug' => 'background-light',
  89. 'color' => '#FAFAFA',
  90. ),
  91. array(
  92. 'name' => __( 'White', 'shawburn' ),
  93. 'slug' => 'background',
  94. 'color' => '#FFFFFF',
  95. ),
  96. )
  97. );
  98. }
  99. endif;
  100. add_action( 'after_setup_theme', 'shawburn_setup', 12 );
  101. /**
  102. * Filter the content_width in pixels, based on the child-theme's design and stylesheet.
  103. */
  104. function shawburn_content_width() {
  105. return 750;
  106. }
  107. add_action( 'after_setup_theme', 'shawburn_content_width' );
  108. /**
  109. * Add Google webfonts, if necessary
  110. *
  111. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  112. */
  113. function shawburn_fonts_url() {
  114. $fonts_url = '';
  115. /* translators: If there are characters in your language that are not supported
  116. * by PT Sans, translate this to 'off'. Do not translate into your own language.
  117. */
  118. $pt_sans = _x( 'on', 'PT Sans font: on or off', 'shawburn' );
  119. /* translators: If there are characters in your language that are not supported
  120. * by PT Serif, translate this to 'off'. Do not translate into your own language.
  121. */
  122. $pt_serif = _x( 'on', 'PT Serif font: on or off', 'shawburn' );
  123. if ( 'off' !== $pt_sans || 'off' !== $pt_serif ) {
  124. $font_families = array();
  125. if ( 'off' !== $pt_sans ) {
  126. $font_families[] = 'PT Sans:400,400i,700,700i';
  127. }
  128. if ( 'off' !== $pt_serif ) {
  129. $font_families[] = 'PT Serif:400,400i,700,700i';
  130. }
  131. $query_args = array(
  132. 'family' => urlencode( implode( '|', $font_families ) ),
  133. 'subset' => urlencode( 'latin,latin-ext' ),
  134. );
  135. $fonts_url = add_query_arg( $query_args, "https://fonts.googleapis.com/css" );
  136. }
  137. return esc_url_raw( $fonts_url );
  138. }
  139. /**
  140. * Enqueue scripts and styles.
  141. */
  142. function shawburn_scripts() {
  143. // enqueue Google fonts
  144. wp_enqueue_style( 'shawburn-fonts', shawburn_fonts_url(), array(), null );
  145. // dequeue parent styles
  146. wp_dequeue_style( 'varia-style' );
  147. // enqueue child styles
  148. wp_enqueue_style('shawburn-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ));
  149. // enqueue child RTL styles
  150. wp_style_add_data( 'shawburn-style', 'rtl', 'replace' );
  151. }
  152. add_action( 'wp_enqueue_scripts', 'shawburn_scripts', 99 );
  153. /**
  154. * Enqueue theme styles for the block editor.
  155. */
  156. function shawburn_editor_styles() {
  157. // Enqueue Google fonts in the editor
  158. wp_enqueue_style( 'shawburn-editor-fonts', shawburn_fonts_url(), array(), null );
  159. }
  160. add_action( 'enqueue_block_editor_assets', 'shawburn_editor_styles' );