functions.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 Balasana
  9. * @since 1.0.0
  10. */
  11. if ( ! function_exists( 'balasana_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 balasana_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', 'balasana' ),
  28. 'shortName' => __( 'S', 'balasana' ),
  29. 'size' => 16.666,
  30. 'slug' => 'small',
  31. ),
  32. array(
  33. 'name' => __( 'Normal', 'balasana' ),
  34. 'shortName' => __( 'M', 'balasana' ),
  35. 'size' => 20,
  36. 'slug' => 'normal',
  37. ),
  38. array(
  39. 'name' => __( 'Large', 'balasana' ),
  40. 'shortName' => __( 'L', 'balasana' ),
  41. 'size' => 28.8,
  42. 'slug' => 'large',
  43. ),
  44. array(
  45. 'name' => __( 'Huge', 'balasana' ),
  46. 'shortName' => __( 'XL', 'balasana' ),
  47. 'size' => 34.56,
  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', 'balasana' ),
  58. 'slug' => 'primary',
  59. 'color' => '#19744C',
  60. ),
  61. array(
  62. 'name' => __( 'Secondary', 'balasana' ),
  63. 'slug' => 'secondary',
  64. 'color' => '#BC2213',
  65. ),
  66. array(
  67. 'name' => __( 'Dark Gray', 'balasana' ),
  68. 'slug' => 'foreground-dark',
  69. 'color' => '#101010',
  70. ),
  71. array(
  72. 'name' => __( 'Gray', 'balasana' ),
  73. 'slug' => 'foreground',
  74. 'color' => '#303030',
  75. ),
  76. array(
  77. 'name' => __( 'Light Gray', 'balasana' ),
  78. 'slug' => 'foreground-light',
  79. 'color' => '#505050',
  80. ),
  81. array(
  82. 'name' => __( 'Lighter Gray', 'balasana' ),
  83. 'slug' => 'background-dark',
  84. 'color' => '#D0D0D0',
  85. ),
  86. array(
  87. 'name' => __( 'Subtle Gray', 'balasana' ),
  88. 'slug' => 'background-light',
  89. 'color' => '#F0F0F0',
  90. ),
  91. array(
  92. 'name' => __( 'White', 'balasana' ),
  93. 'slug' => 'background',
  94. 'color' => '#FFFFFF',
  95. ),
  96. )
  97. );
  98. // Add child theme support for core custom logo.
  99. add_theme_support(
  100. 'custom-logo',
  101. array(
  102. 'height' => 96,
  103. 'width' => 96,
  104. 'flex-width' => true,
  105. 'flex-height' => true,
  106. 'header-text' => array( 'site-title', 'site-description' ),
  107. )
  108. );
  109. }
  110. endif;
  111. add_action( 'after_setup_theme', 'balasana_setup', 12 );
  112. /**
  113. * Filter the content_width in pixels, based on the child-theme's design and stylesheet.
  114. */
  115. function balasana_content_width() {
  116. return 750;
  117. }
  118. add_filter( 'varia_content_width', 'balasana_content_width' );
  119. /**
  120. * Add Google webfonts
  121. *
  122. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  123. */
  124. function balasana_fonts_url() {
  125. $fonts_url = '';
  126. /* Translators: If there are characters in your language that are not
  127. * supported by Roboto Condensed, translate this to 'off'. Do not translate
  128. * into your own language.
  129. */
  130. $roboto_condensed = esc_html_x( 'on', 'Roboto Condensed font: on or off', 'balasana' );
  131. /* Translators: If there are characters in your language that are not
  132. * supported by Roboto, translate this to 'off'. Do not translate
  133. * into your own language.
  134. */
  135. $roboto = esc_html_x( 'on', 'Roboto font: on or off', 'balasana' );
  136. if ( 'off' !== $roboto_condensed || 'off' !== $roboto ) {
  137. $font_families = array();
  138. if ( 'off' !== $roboto_condensed ) {
  139. $font_families[] = 'Roboto Condensed:400,400i,700,700i';
  140. }
  141. if ( 'off' !== $roboto ) {
  142. $font_families[] = 'Roboto:400,400i,700,700i';
  143. }
  144. $query_args = array(
  145. 'family' => urlencode( implode( '|', $font_families ) ),
  146. 'subset' => urlencode( 'latin,latin-ext' ),
  147. );
  148. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  149. }
  150. return esc_url_raw( $fonts_url );
  151. }
  152. /**
  153. * Enqueue scripts and styles.
  154. */
  155. function balasana_scripts() {
  156. // enqueue Google fonts
  157. wp_enqueue_style( 'balasana-fonts', balasana_fonts_url(), array(), null );
  158. // dequeue parent styles
  159. wp_dequeue_style( 'varia-style' );
  160. // enqueue child styles
  161. wp_enqueue_style('balasana-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ));
  162. // enqueue child RTL styles
  163. wp_style_add_data( 'balasana-style', 'rtl', 'replace' );
  164. }
  165. add_action( 'wp_enqueue_scripts', 'balasana_scripts', 99 );
  166. /**
  167. * Enqueue theme styles for the block editor.
  168. */
  169. function balasana_editor_styles() {
  170. // Enqueue Google fonts in the editor
  171. wp_enqueue_style( 'balasana-editor-fonts', balasana_fonts_url(), array(), null );
  172. }
  173. add_action( 'enqueue_block_editor_assets', 'balasana_editor_styles' );