functions.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 Hever
  9. * @since 1.0.0
  10. */
  11. if ( ! function_exists( 'varia_default_colors' ) ) {
  12. function varia_default_colors() {
  13. return array(
  14. 'background' => '#FFFFFF',
  15. 'foreground' => '#303030',
  16. 'primary' => '#1279BE',
  17. 'secondary' => '#FFB302',
  18. 'tertiary' => '#C5C5C5',
  19. );
  20. }
  21. }
  22. if ( ! function_exists( 'hever_setup' ) ) :
  23. /**
  24. * Sets up theme defaults and registers support for various WordPress features.
  25. *
  26. * Note that this function is hooked into the after_setup_theme hook, which
  27. * runs before the init hook. The init hook is too late for some features, such
  28. * as indicating support for post thumbnails.
  29. */
  30. function hever_setup() {
  31. // Add child theme editor styles, compiled from `style-child-theme-editor.scss`.
  32. add_editor_style( 'style-editor.css' );
  33. // Add child theme editor font sizes to match Sass-map variables in `_config-child-theme-deep.scss`.
  34. add_theme_support(
  35. 'editor-font-sizes',
  36. array(
  37. array(
  38. 'name' => __( 'Small', 'hever' ),
  39. 'shortName' => __( 'S', 'hever' ),
  40. 'size' => 17.3914,
  41. 'slug' => 'small',
  42. ),
  43. array(
  44. 'name' => __( 'Medium', 'hever' ),
  45. 'shortName' => __( 'M', 'hever' ),
  46. 'size' => 23,
  47. 'slug' => 'normal',
  48. ),
  49. array(
  50. 'name' => __( 'Large', 'hever' ),
  51. 'shortName' => __( 'L', 'hever' ),
  52. 'size' => 26.45,
  53. 'slug' => 'large',
  54. ),
  55. array(
  56. 'name' => __( 'Huge', 'hever' ),
  57. 'shortName' => __( 'XL', 'hever' ),
  58. 'size' => 30.4174,
  59. 'slug' => 'huge',
  60. ),
  61. )
  62. );
  63. // Setup nav on side toggle support.
  64. if ( function_exists( 'varia_mobile_nav_on_side_setup' ) ) {
  65. varia_mobile_nav_on_side_setup();
  66. }
  67. // Add support for link color control.
  68. add_theme_support( 'link-color' );
  69. }
  70. endif;
  71. add_action( 'after_setup_theme', 'hever_setup', 12 );
  72. /**
  73. * Set the content width in pixels, based on the child-theme's design and stylesheet.
  74. *
  75. * Priority 0 to make it available to lower priority callbacks.
  76. *
  77. * @global int $content_width Content width.
  78. */
  79. function hever_content_width() {
  80. // This variable is intended to be overruled from themes.
  81. // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
  82. // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
  83. $GLOBALS['content_width'] = apply_filters( 'hever_content_width', 740 );
  84. }
  85. add_action( 'after_setup_theme', 'hever_content_width', 0 );
  86. /**
  87. * Add Google webfonts, if necessary
  88. *
  89. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  90. */
  91. function hever_fonts_url() {
  92. $fonts_url = '';
  93. /* Translators: If there are characters in your language that are not
  94. * supported by PT Sans, translate this to 'off'. Do not translate
  95. * into your own language.
  96. */
  97. $ptsans = esc_html_x( 'on', 'PT Sans font: on or off', 'hever' );
  98. if ( 'off' !== $ptsans ) {
  99. $font_families = array();
  100. $font_families[] = 'PT Sans:400,400i,700,700i';
  101. /**
  102. * A filter to enable child themes to add/change/omit font families.
  103. *
  104. * @param array $font_families An array of font families to be imploded for the Google Font API
  105. */
  106. $font_families = apply_filters( 'included_google_font_families', $font_families );
  107. $query_args = array(
  108. 'family' => urlencode( implode( '|', $font_families ) ),
  109. 'subset' => urlencode( 'latin,latin-ext' ),
  110. 'display' => 'swap',
  111. );
  112. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  113. }
  114. return esc_url_raw( $fonts_url );
  115. }
  116. /**
  117. * Enqueue scripts and styles.
  118. */
  119. function hever_scripts() {
  120. // enqueue Google fonts
  121. wp_enqueue_style( 'hever-fonts', hever_fonts_url(), array(), null );
  122. // dequeue parent styles
  123. wp_dequeue_style( 'varia-style' );
  124. // enqueue child styles
  125. wp_enqueue_style( 'hever-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
  126. // enqueue child RTL styles
  127. wp_style_add_data( 'hever-style', 'rtl', 'replace' );
  128. }
  129. add_action( 'wp_enqueue_scripts', 'hever_scripts', 99 );
  130. /**
  131. * Enqueue theme styles for the block editor.
  132. */
  133. function hever_editor_styles() {
  134. // enqueue Google fonts in the editor
  135. wp_enqueue_style( 'hever-editor-fonts', hever_fonts_url(), array(), null );
  136. }
  137. add_action( 'enqueue_block_editor_assets', 'hever_editor_styles' );