functions.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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 Alves
  9. * @since 1.0.0
  10. */
  11. if ( ! function_exists( 'alves_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 alves_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', 'alves' ),
  28. 'shortName' => __( 'S', 'alves' ),
  29. 'size' => 16.6667,
  30. 'slug' => 'small',
  31. ),
  32. array(
  33. 'name' => __( 'Normal', 'alves' ),
  34. 'shortName' => __( 'M', 'alves' ),
  35. 'size' => 20,
  36. 'slug' => 'normal',
  37. ),
  38. array(
  39. 'name' => __( 'Large', 'alves' ),
  40. 'shortName' => __( 'L', 'alves' ),
  41. 'size' => 28.8,
  42. 'slug' => 'large',
  43. ),
  44. array(
  45. 'name' => __( 'Huge', 'alves' ),
  46. 'shortName' => __( 'XL', 'alves' ),
  47. 'size' => 34.5667,
  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', 'alves' ),
  58. 'slug' => 'primary',
  59. 'color' => '#3E7D98',
  60. ),
  61. array(
  62. 'name' => __( 'Secondary', 'alves' ),
  63. 'slug' => 'secondary',
  64. 'color' => '#9B6A36',
  65. ),
  66. array(
  67. 'name' => __( 'Dark Gray', 'alves' ),
  68. 'slug' => 'foreground-dark',
  69. 'color' => '#253136',
  70. ),
  71. array(
  72. 'name' => __( 'Gray', 'alves' ),
  73. 'slug' => 'foreground',
  74. 'color' => '#394d55',
  75. ),
  76. array(
  77. 'name' => __( 'Light Gray', 'alves' ),
  78. 'slug' => 'foreground-light',
  79. 'color' => '#4d6974',
  80. ),
  81. array(
  82. 'name' => __( 'White', 'alves' ),
  83. 'slug' => 'background',
  84. 'color' => '#ffffff',
  85. ),
  86. )
  87. );
  88. }
  89. endif;
  90. add_action( 'after_setup_theme', 'alves_setup', 12 );
  91. /**
  92. * Register second and third footer widget area.
  93. *
  94. * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar
  95. */
  96. function alves_widgets_init() {
  97. register_sidebar(
  98. array(
  99. 'name' => __( 'Footer 2', 'alves' ),
  100. 'id' => 'sidebar-2',
  101. 'description' => __( 'Add widgets here to appear in your footer.', 'alves' ),
  102. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  103. 'after_widget' => '</section>',
  104. 'before_title' => '<h2 class="widget-title">',
  105. 'after_title' => '</h2>',
  106. )
  107. );
  108. register_sidebar(
  109. array(
  110. 'name' => __( 'Footer 3', 'alves' ),
  111. 'id' => 'sidebar-3',
  112. 'description' => __( 'Add widgets here to appear in your footer.', 'alves' ),
  113. 'before_widget' => '<section id="%1$s" class="widget %2$s">',
  114. 'after_widget' => '</section>',
  115. 'before_title' => '<h2 class="widget-title">',
  116. 'after_title' => '</h2>',
  117. )
  118. );
  119. }
  120. add_action( 'widgets_init', 'alves_widgets_init', 12 );
  121. /**
  122. * Filter the content_width in pixels, based on the child-theme's design and stylesheet.
  123. */
  124. function alves_content_width() {
  125. return 700;
  126. }
  127. add_filter( 'varia_content_width', 'alves_content_width' );
  128. /**
  129. * Add Google webfonts, if necessary
  130. *
  131. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  132. */
  133. function alves_fonts_url() {
  134. $fonts_url = '';
  135. /* Translators: If there are characters in your language that are not
  136. * supported by Lora, translate this to 'off'. Do not translate
  137. * into your own language.
  138. */
  139. $lora = esc_html_x( 'on', 'Lora font: on or off', 'alves' );
  140. /* Translators: If there are characters in your language that are not
  141. * supported by Karla, translate this to 'off'. Do not translate
  142. * into your own language.
  143. */
  144. $karla = esc_html_x( 'on', 'Karla font: on or off', 'alves' );
  145. if ( 'off' !== $lora || 'off' !== $karla ) {
  146. $font_families = array();
  147. if ( 'off' !== $lora ) {
  148. $font_families[] = 'Lora:400,700,400italic,700italic';
  149. }
  150. if ( 'off' !== $karla ) {
  151. $font_families[] = 'Karla:400,700,400italic,700italic';
  152. }
  153. $query_args = array(
  154. 'family' => urlencode( implode( '|', $font_families ) ),
  155. 'subset' => urlencode( 'latin,latin-ext' ),
  156. );
  157. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  158. }
  159. return esc_url_raw( $fonts_url );
  160. }
  161. /**
  162. * Enqueue scripts and styles.
  163. */
  164. function alves_scripts() {
  165. // enqueue Google fonts, if necessary
  166. wp_enqueue_style( 'alves-fonts', alves_fonts_url(), array(), null );
  167. // dequeue parent styles
  168. wp_dequeue_style( 'varia-style' );
  169. // enqueue child styles
  170. wp_enqueue_style('alves-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ));
  171. // enqueue child RTL styles
  172. wp_style_add_data( 'alves-style', 'rtl', 'replace' );
  173. }
  174. add_action( 'wp_enqueue_scripts', 'alves_scripts', 99 );
  175. /**
  176. * Enqueue theme styles for the block editor.
  177. */
  178. function alves_editor_styles() {
  179. // Enqueue Google fonts in the editor, if necessary
  180. wp_enqueue_style( 'alves-editor-fonts', alves_fonts_url(), array(), null );
  181. }
  182. add_action( 'enqueue_block_editor_assets', 'alves_editor_styles' );