functions.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 Coutoire
  9. * @since 1.0.0
  10. */
  11. if ( ! function_exists( 'coutoire_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 coutoire_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', 'coutoire' ),
  28. 'shortName' => __( 'S', 'coutoire' ),
  29. 'size' => 19.5,
  30. 'slug' => 'small',
  31. ),
  32. array(
  33. 'name' => __( 'Normal', 'coutoire' ),
  34. 'shortName' => __( 'M', 'coutoire' ),
  35. 'size' => 22,
  36. 'slug' => 'normal',
  37. ),
  38. array(
  39. 'name' => __( 'Large', 'coutoire' ),
  40. 'shortName' => __( 'L', 'coutoire' ),
  41. 'size' => 36.5,
  42. 'slug' => 'large',
  43. ),
  44. array(
  45. 'name' => __( 'Huge', 'coutoire' ),
  46. 'shortName' => __( 'XL', 'coutoire' ),
  47. 'size' => 49.5,
  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', 'coutoire' ),
  58. 'slug' => 'primary',
  59. 'color' => '#0000FF', // varia_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? $default_hue : get_theme_mod( 'primary_color_hue', $default_hue ), $saturation, $lightness ),
  60. ),
  61. array(
  62. 'name' => __( 'Secondary', 'coutoire' ),
  63. 'slug' => 'secondary',
  64. 'color' => '#FF0000', // varia_hsl_hex( 'default' === get_theme_mod( 'primary_color' ) ? $default_hue : get_theme_mod( 'primary_color_hue', $default_hue ), $saturation, $lightness_hover ),
  65. ),
  66. array(
  67. 'name' => __( 'Dark Gray', 'coutoire' ),
  68. 'slug' => 'foreground-dark',
  69. 'color' => '#111111',
  70. ),
  71. array(
  72. 'name' => __( 'Gray', 'coutoire' ),
  73. 'slug' => 'foreground',
  74. 'color' => '#444444',
  75. ),
  76. array(
  77. 'name' => __( 'Light Gray', 'coutoire' ),
  78. 'slug' => 'foreground-light',
  79. 'color' => '#767676',
  80. ),
  81. array(
  82. 'name' => __( 'White', 'coutoire' ),
  83. 'slug' => 'background',
  84. 'color' => '#FFFFFF',
  85. ),
  86. )
  87. );
  88. }
  89. endif;
  90. add_action( 'after_setup_theme', 'coutoire_setup' );
  91. /**
  92. * Filter the content_width in pixels, based on the child-theme's design and stylesheet.
  93. */
  94. function coutoire_content_width() {
  95. return 1200;
  96. }
  97. add_filter( 'varia_content_width', 'coutoire_content_width' );
  98. /**
  99. * Add Google webfonts, if necessary
  100. *
  101. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  102. */
  103. function coutoire_fonts_url() {
  104. $fonts_url = '';
  105. /* Translators: If there are characters in your language that are not
  106. * supported by Lora, translate this to 'off'. Do not translate
  107. * into your own language.
  108. */
  109. $work_sans = esc_html_x( 'on', 'Work Sans font: on or off', 'coutoire' );
  110. /* Translators: If there are characters in your language that are not
  111. * supported by Open Sans, translate this to 'off'. Do not translate
  112. * into your own language.
  113. */
  114. $eb_garamond = esc_html_x( 'on', 'EB Garamond font: on or off', 'coutoire' );
  115. if ( 'off' !== $work_sans || 'off' !== $eb_garamond ) {
  116. $font_families = array();
  117. if ( 'off' !== $work_sans ) {
  118. $font_families[] = 'Work Sans:300,500,600';
  119. }
  120. if ( 'off' !== $eb_garamond ) {
  121. $font_families[] = 'EB Garamond:400,400i';
  122. }
  123. $query_args = array(
  124. 'family' => urlencode( implode( '|', $font_families ) ),
  125. 'subset' => urlencode( 'latin,latin-ext' ),
  126. );
  127. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  128. }
  129. return esc_url_raw( $fonts_url );
  130. }
  131. /**
  132. * Enqueue scripts and styles.
  133. */
  134. function coutoire_scripts() {
  135. // enqueue Google fonts, if necessary
  136. wp_enqueue_style( 'coutoire-fonts', coutoire_fonts_url(), array(), null );
  137. // dequeue parent styles
  138. wp_dequeue_style( 'varia-style' );
  139. // enqueue child styles
  140. wp_enqueue_style('coutoire-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ));
  141. // enqueue child RTL styles
  142. wp_style_add_data( 'coutoire-style', 'rtl', 'replace' );
  143. // enqueue header spacing JS
  144. wp_enqueue_script('coutoire-fixed-header-spacing', get_stylesheet_directory_uri() . '/js/fixed-header-spacing.js', array(), wp_get_theme()->get( 'Version' ), true );
  145. }
  146. add_action( 'wp_enqueue_scripts', 'coutoire_scripts', 99 );
  147. /**
  148. * Enqueue theme styles for the block editor.
  149. */
  150. function coutoire_editor_styles() {
  151. // Enqueue Google fonts in the editor, if necessary
  152. wp_enqueue_style( 'coutoire-editor-fonts', coutoire_fonts_url(), array(), null );
  153. }
  154. add_action( 'enqueue_block_editor_assets', 'coutoire_editor_styles' );