functions.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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 Rivington
  9. * @since 1.0.0
  10. */
  11. if ( ! function_exists( 'rivington_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 rivington_setup() {
  20. // Add child theme editor styles, compiled from `style-child-theme-editor.scss`.
  21. add_editor_style( 'style-editor.css' );
  22. // Dark backgrounds
  23. // - See: https://developer.wordpress.org/block-editor/developers/themes/theme-support/#dark-backgrounds
  24. add_theme_support( 'editor-styles' );
  25. add_theme_support( 'dark-editor-style' );
  26. // Add child theme editor font sizes to match Sass-map variables in `_config-child-theme-deep.scss`.
  27. add_theme_support(
  28. 'editor-font-sizes',
  29. array(
  30. array(
  31. 'name' => __( 'Small', 'rivington' ),
  32. 'shortName' => __( 'S', 'rivington' ),
  33. 'size' => 14.4,
  34. 'slug' => 'small',
  35. ),
  36. array(
  37. 'name' => __( 'Normal', 'rivington' ),
  38. 'shortName' => __( 'M', 'rivington' ),
  39. 'size' => 18,
  40. 'slug' => 'normal',
  41. ),
  42. array(
  43. 'name' => __( 'Large', 'rivington' ),
  44. 'shortName' => __( 'L', 'rivington' ),
  45. 'size' => 28.12,
  46. 'slug' => 'large',
  47. ),
  48. array(
  49. 'name' => __( 'Huge', 'rivington' ),
  50. 'shortName' => __( 'XL', 'rivington' ),
  51. 'size' => 35.15,
  52. 'slug' => 'huge',
  53. ),
  54. )
  55. );
  56. // Add child theme editor color pallete to match Sass-map variables in `_config-child-theme-deep.scss`.
  57. add_theme_support(
  58. 'editor-color-palette',
  59. array(
  60. array(
  61. 'name' => __( 'Primary', 'rivington' ),
  62. 'slug' => 'primary',
  63. 'color' => '#CAAB57',
  64. ),
  65. array(
  66. 'name' => __( 'Secondary', 'rivington' ),
  67. 'slug' => 'secondary',
  68. 'color' => '#EE4266',
  69. ),
  70. array(
  71. 'name' => __( 'Light Gray', 'rivington' ),
  72. 'slug' => 'foreground-dark',
  73. 'color' => '#8F8F8F',
  74. ),
  75. array(
  76. 'name' => __( 'Off White', 'rivington' ),
  77. 'slug' => 'foreground',
  78. 'color' => '#F2F2F2',
  79. ),
  80. array(
  81. 'name' => __( 'White', 'rivington' ),
  82. 'slug' => 'foreground-light',
  83. 'color' => '#FFFFFF',
  84. ),
  85. array(
  86. 'name' => __( 'Dark Navy', 'rivington' ),
  87. 'slug' => 'background-dark',
  88. 'color' => '#030713',
  89. ),
  90. array(
  91. 'name' => __( 'Navy', 'rivington' ),
  92. 'slug' => 'background',
  93. 'color' => '#060f29',
  94. ),
  95. array(
  96. 'name' => __( 'Light Navy', 'rivington' ),
  97. 'slug' => 'background-light',
  98. 'color' => '#0d1f55',
  99. ),
  100. )
  101. );
  102. // Remove footer menu
  103. unregister_nav_menu( 'menu-2' );
  104. }
  105. endif;
  106. add_action( 'after_setup_theme', 'rivington_setup', 12 );
  107. /**
  108. * Filter the content_width in pixels, based on the child-theme's design and stylesheet.
  109. */
  110. function rivington_content_width() {
  111. return 750;
  112. }
  113. add_filter( 'varia_content_width', 'rivington_content_width' );
  114. /**
  115. * Add Google webfonts, if necessary
  116. *
  117. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  118. */
  119. function rivington_fonts_url() {
  120. $fonts_url = '';
  121. /* Translators: If there are characters in your language that are not
  122. * supported by Playfair Display, translate this to 'off'. Do not translate
  123. * into your own language.
  124. */
  125. $playfair = esc_html_x( 'on', 'Playfair Display font: on or off', 'rivington' );
  126. /* Translators: If there are characters in your language that are not
  127. * supported by Roboto Sans, translate this to 'off'. Do not translate
  128. * into your own language.
  129. */
  130. $roboto = esc_html_x( 'on', 'Roboto Sans font: on or off', 'rivington' );
  131. if ( 'off' !== $playfair || 'off' !== $roboto ) {
  132. $font_families = array();
  133. if ( 'off' !== $playfair ) {
  134. $font_families[] = 'Playfair+Display:400,400i';
  135. }
  136. if ( 'off' !== $roboto ) {
  137. $font_families[] = 'Roboto:300,300i,700';
  138. }
  139. $query_args = array(
  140. 'family' => urlencode( implode( '|', $font_families ) ),
  141. 'subset' => urlencode( 'latin,latin-ext' ),
  142. );
  143. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  144. }
  145. return esc_url_raw( $fonts_url );
  146. }
  147. /**
  148. * Enqueue scripts and styles.
  149. */
  150. function rivington_scripts() {
  151. // enqueue Google fonts, if necessary
  152. // wp_enqueue_style( 'rivington-fonts', rivington_fonts_url(), array(), null );
  153. // dequeue parent styles
  154. wp_dequeue_style( 'varia-style' );
  155. // enqueue child styles
  156. wp_enqueue_style('rivington-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ));
  157. // enqueue child RTL styles
  158. wp_style_add_data( 'rivington-style', 'rtl', 'replace' );
  159. }
  160. add_action( 'wp_enqueue_scripts', 'rivington_scripts', 99 );
  161. /**
  162. * Enqueue theme styles for the block editor.
  163. */
  164. function rivington_editor_styles() {
  165. // Enqueue Google fonts in the editor, if necessary
  166. wp_enqueue_style( 'rivington-editor-fonts', rivington_fonts_url(), array(), null );
  167. }
  168. add_action( 'enqueue_block_editor_assets', 'rivington_editor_styles' );