functions.php 5.4 KB

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