functions.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 Leven
  9. * @since 1.0.0
  10. */
  11. if ( ! function_exists( 'leven_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 leven_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', 'leven' ),
  28. 'shortName' => __( 'S', 'leven' ),
  29. 'size' => 15,
  30. 'slug' => 'small',
  31. ),
  32. array(
  33. 'name' => __( 'Normal', 'leven' ),
  34. 'shortName' => __( 'M', 'leven' ),
  35. 'size' => 18,
  36. 'slug' => 'normal',
  37. ),
  38. array(
  39. 'name' => __( 'Large', 'leven' ),
  40. 'shortName' => __( 'L', 'leven' ),
  41. 'size' => 32,
  42. 'slug' => 'large',
  43. ),
  44. array(
  45. 'name' => __( 'Huge', 'leven' ),
  46. 'shortName' => __( 'XL', 'leven' ),
  47. 'size' => 47.17,
  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', 'leven' ),
  58. 'slug' => 'primary',
  59. 'color' => '#FF302C',
  60. ),
  61. array(
  62. 'name' => __( 'Secondary', 'leven' ),
  63. 'slug' => 'secondary',
  64. 'color' => '#1285CE',
  65. ),
  66. array(
  67. 'name' => __( 'Dark Gray', 'leven' ),
  68. 'slug' => 'foreground-dark',
  69. 'color' => '#111111',
  70. ),
  71. array(
  72. 'name' => __( 'Gray', 'leven' ),
  73. 'slug' => 'foreground',
  74. 'color' => '#444444',
  75. ),
  76. array(
  77. 'name' => __( 'Light Gray', 'leven' ),
  78. 'slug' => 'foreground-light',
  79. 'color' => '#767676',
  80. ),
  81. array(
  82. 'name' => __( 'Lighter Gray', 'varia' ),
  83. 'slug' => 'background-dark',
  84. 'color' => '#DDDDDD',
  85. ),
  86. array(
  87. 'name' => __( 'White', 'varia' ),
  88. 'slug' => 'background-light',
  89. 'color' => '#FFFFFF',
  90. ),
  91. array(
  92. 'name' => __( 'Subtle Gray', 'leven' ),
  93. 'slug' => 'background',
  94. 'color' => '#F7F7F6',
  95. ),
  96. )
  97. );
  98. }
  99. endif;
  100. add_action( 'after_setup_theme', 'leven_setup', 12 );
  101. /**
  102. * Set the content width in pixels, based on the child-theme's design and stylesheet.
  103. *
  104. * Priority 0 to make it available to lower priority callbacks.
  105. *
  106. * @global int $content_width Content width.
  107. */
  108. function leven_content_width() {
  109. // This variable is intended to be overruled from themes.
  110. // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
  111. // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
  112. $GLOBALS['content_width'] = apply_filters( 'leven_content_width', 640 );
  113. }
  114. add_action( 'after_setup_theme', 'leven_content_width', 0 );
  115. /**
  116. * Add Google webfonts, if necessary
  117. *
  118. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  119. */
  120. function leven_fonts_url() {
  121. $fonts_url = '';
  122. /* Translators: If there are characters in your language that are not
  123. * supported by Lora, translate this to 'off'. Do not translate
  124. * into your own language.
  125. */
  126. $crimson_text = esc_html_x( 'on', 'Crimson Text font: on or off', 'leven' );
  127. if ( 'off' !== $crimson_text ) {
  128. $font_families = array();
  129. if ( 'off' !== $crimson_text ) {
  130. $font_families[] = 'Crimson Text:400,400i';
  131. }
  132. $query_args = array(
  133. 'family' => urlencode( implode( '|', $font_families ) ),
  134. 'subset' => urlencode( 'latin,latin-ext' ),
  135. );
  136. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  137. }
  138. return esc_url_raw( $fonts_url );
  139. }
  140. /**
  141. * Enqueue scripts and styles.
  142. */
  143. function leven_scripts() {
  144. // enqueue Google fonts, if necessary
  145. wp_enqueue_style( 'leven-fonts', leven_fonts_url(), array(), null );
  146. // dequeue parent styles
  147. wp_dequeue_style( 'varia-style' );
  148. // enqueue child styles
  149. wp_enqueue_style('leven-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ));
  150. // enqueue child RTL styles
  151. wp_style_add_data( 'leven-style', 'rtl', 'replace' );
  152. }
  153. add_action( 'wp_enqueue_scripts', 'leven_scripts', 99 );
  154. /**
  155. * Enqueue theme styles for the block editor.
  156. */
  157. function leven_editor_styles() {
  158. // Enqueue Google fonts in the editor, if necessary
  159. wp_enqueue_style( 'leven-editor-fonts', leven_fonts_url(), array(), null );
  160. }
  161. add_action( 'enqueue_block_editor_assets', 'leven_editor_styles' );