functions.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 Maywood
  9. * @since 1.0.0
  10. */
  11. if ( ! function_exists( 'maywood_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 maywood_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', 'maywood' ),
  28. 'shortName' => __( 'S', 'maywood' ),
  29. 'size' => 16.6,
  30. 'slug' => 'small',
  31. ),
  32. array(
  33. 'name' => __( 'Normal', 'maywood' ),
  34. 'shortName' => __( 'M', 'maywood' ),
  35. 'size' => 20,
  36. 'slug' => 'normal',
  37. ),
  38. array(
  39. 'name' => __( 'Large', 'maywood' ),
  40. 'shortName' => __( 'L', 'maywood' ),
  41. 'size' => 28.8,
  42. 'slug' => 'large',
  43. ),
  44. array(
  45. 'name' => __( 'Huge', 'maywood' ),
  46. 'shortName' => __( 'XL', 'maywood' ),
  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', 'maywood' ),
  58. 'slug' => 'primary',
  59. 'color' => '#897248',
  60. ),
  61. array(
  62. 'name' => __( 'Secondary', 'maywood' ),
  63. 'slug' => 'secondary',
  64. 'color' => '#c4493f',
  65. ),
  66. array(
  67. 'name' => __( 'Black', 'maywood' ),
  68. 'slug' => 'foreground-dark',
  69. 'color' => '#020202',
  70. ),
  71. array(
  72. 'name' => __( 'Dark Gray', 'maywood' ),
  73. 'slug' => 'foreground',
  74. 'color' => '#181818',
  75. ),
  76. array(
  77. 'name' => __( 'Gray', 'maywood' ),
  78. 'slug' => 'foreground-light',
  79. 'color' => '#686868',
  80. ),
  81. array(
  82. 'name' => __( 'Light Gray', 'maywood' ),
  83. 'slug' => 'background-dark',
  84. 'color' => '#CCCCCC',
  85. ),
  86. array(
  87. 'name' => __( 'Subtle Gray', 'maywood' ),
  88. 'slug' => 'background-light',
  89. 'color' => '#F7F7F7',
  90. ),
  91. array(
  92. 'name' => __( 'White', 'maywood' ),
  93. 'slug' => 'background',
  94. 'color' => '#FFFFFF',
  95. ),
  96. )
  97. );
  98. // Enable Full Site Editing
  99. add_theme_support( 'full-site-editing');
  100. }
  101. endif;
  102. add_action( 'after_setup_theme', 'maywood_setup', 12 );
  103. /**
  104. * Filter the content_width in pixels, based on the child-theme's design and stylesheet.
  105. */
  106. function maywood_content_width() {
  107. return 750;
  108. }
  109. add_filter( 'varia_content_width', 'maywood_content_width' );
  110. /**
  111. * Add Google webfonts, if necessary
  112. *
  113. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  114. */
  115. function maywood_fonts_url() {
  116. $fonts_url = '';
  117. /* Translators: If there are characters in your language that are not
  118. * supported by IBM Plex Sans, translate this to 'off'. Do not translate
  119. * into your own language.
  120. */
  121. $ibm_plex_sans = esc_html_x( 'on', 'IBM Plex Sans font: on or off', 'maywood' );
  122. if ( 'off' !== $ibm_plex_sans ) {
  123. $font_families = array();
  124. $font_families[] = 'IBM Plex Sans:300,300i,500,500i,700';
  125. $query_args = array(
  126. 'family' => urlencode( implode( '|', $font_families ) ),
  127. 'subset' => urlencode( 'latin,latin-ext' ),
  128. );
  129. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  130. }
  131. return esc_url_raw( $fonts_url );
  132. }
  133. /**
  134. * Enqueue scripts and styles.
  135. */
  136. function maywood_scripts() {
  137. // enqueue Google fonts, if necessary
  138. wp_enqueue_style( 'maywood-fonts', maywood_fonts_url(), array(), null );
  139. // dequeue parent styles
  140. wp_dequeue_style( 'varia-style' );
  141. // enqueue child styles
  142. wp_enqueue_style('maywood-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ));
  143. // enqueue child RTL styles
  144. wp_style_add_data( 'maywood-style', 'rtl', 'replace' );
  145. }
  146. add_action( 'wp_enqueue_scripts', 'maywood_scripts', 99 );
  147. /**
  148. * Enqueue theme styles for the block editor.
  149. */
  150. function maywood_editor_styles() {
  151. // Enqueue Google fonts in the editor, if necessary
  152. wp_enqueue_style( 'maywood-editor-fonts', maywood_fonts_url(), array(), null );
  153. }
  154. add_action( 'enqueue_block_editor_assets', 'maywood_editor_styles' );