functions.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. }
  68. endif;
  69. add_action( 'after_setup_theme', 'hever_setup', 12 );
  70. /**
  71. * Set the content width in pixels, based on the child-theme's design and stylesheet.
  72. *
  73. * Priority 0 to make it available to lower priority callbacks.
  74. *
  75. * @global int $content_width Content width.
  76. */
  77. function hever_content_width() {
  78. // This variable is intended to be overruled from themes.
  79. // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
  80. // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
  81. $GLOBALS['content_width'] = apply_filters( 'hever_content_width', 740 );
  82. }
  83. add_action( 'after_setup_theme', 'hever_content_width', 0 );
  84. /**
  85. * Add Google webfonts, if necessary
  86. *
  87. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  88. */
  89. function hever_fonts_url() {
  90. $fonts_url = '';
  91. /* Translators: If there are characters in your language that are not
  92. * supported by PT Sans, translate this to 'off'. Do not translate
  93. * into your own language.
  94. */
  95. $ptsans = esc_html_x( 'on', 'PT Sans font: on or off', 'hever' );
  96. if ( 'off' !== $ptsans ) {
  97. $font_families = array();
  98. $font_families[] = 'PT Sans:400,400i,700,700i';
  99. $query_args = array(
  100. 'family' => urlencode( implode( '|', $font_families ) ),
  101. 'subset' => urlencode( 'latin,latin-ext' ),
  102. 'display' => 'swap',
  103. );
  104. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  105. }
  106. return esc_url_raw( $fonts_url );
  107. }
  108. /**
  109. * Enqueue scripts and styles.
  110. */
  111. function hever_scripts() {
  112. // enqueue Google fonts
  113. wp_enqueue_style( 'hever-fonts', hever_fonts_url(), array(), null );
  114. // dequeue parent styles
  115. wp_dequeue_style( 'varia-style' );
  116. // enqueue child styles
  117. wp_enqueue_style( 'hever-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
  118. // enqueue child RTL styles
  119. wp_style_add_data( 'hever-style', 'rtl', 'replace' );
  120. }
  121. add_action( 'wp_enqueue_scripts', 'hever_scripts', 99 );
  122. /**
  123. * Enqueue theme styles for the block editor.
  124. */
  125. function hever_editor_styles() {
  126. // enqueue Google fonts in the editor
  127. wp_enqueue_style( 'hever-editor-fonts', hever_fonts_url(), array(), null );
  128. }
  129. add_action( 'enqueue_block_editor_assets', 'hever_editor_styles' );