functions.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. * @since 1.0.0
  9. */
  10. if ( ! function_exists( 'redhill_theme_setup' ) ) :
  11. /**
  12. * Sets up theme defaults and registers support for various WordPress features.
  13. *
  14. * Note that this function is hooked into the after_setup_theme hook, which
  15. * runs before the init hook. The init hook is too late for some features, such
  16. * as indicating support for post thumbnails.
  17. */
  18. function redhill_theme_setup() {
  19. // Add child theme editor styles, compiled from `style-child-theme-editor.scss`.
  20. add_editor_style( 'style-editor.css' );
  21. // Remove parent theme font sizes
  22. remove_theme_support( 'editor-font-sizes' );
  23. // Add child theme editor font sizes to match Sass-map variables in `_config-child-theme-deep.scss`.
  24. add_theme_support(
  25. 'editor-font-sizes',
  26. array(
  27. array(
  28. 'name' => __( 'Small', 'redhill' ),
  29. 'shortName' => __( 'S', 'redhill' ),
  30. 'size' => 16.66,
  31. 'slug' => 'small',
  32. ),
  33. array(
  34. 'name' => __( 'Normal', 'redhill' ),
  35. 'shortName' => __( 'N', 'redhill' ),
  36. 'size' => 20,
  37. 'slug' => 'normal',
  38. ),
  39. array(
  40. 'name' => __( 'Medium', 'redhill' ),
  41. 'shortName' => __( 'M', 'redhill' ),
  42. 'size' => 24,
  43. 'slug' => 'medium',
  44. ),
  45. array(
  46. 'name' => __( 'Large', 'redhill' ),
  47. 'shortName' => __( 'L', 'redhill' ),
  48. 'size' => 28.8,
  49. 'slug' => 'large',
  50. ),
  51. array(
  52. 'name' => __( 'Huge', 'redhill' ),
  53. 'shortName' => __( 'XL', 'redhill' ),
  54. 'size' => 34.56,
  55. 'slug' => 'huge',
  56. ),
  57. )
  58. );
  59. /*
  60. * Get customizer colors and add them to the editor color palettes
  61. *
  62. * - if the customizer color is empty, use the default
  63. */
  64. $colors_array = get_theme_mod( 'colors_manager' ); // color annotations array()
  65. $primary = ! empty( $colors_array ) ? $colors_array['colors']['link'] : '#CA2017'; // $config-global--color-primary-default;
  66. $secondary = ! empty( $colors_array ) ? $colors_array['colors']['fg1'] : '#007FDB'; // $config-global--color-secondary-default;
  67. $foreground = ! empty( $colors_array ) ? $colors_array['colors']['txt'] : '#444444'; // $config-global--color-foreground-default;
  68. $background = ! empty( $colors_array ) ? $colors_array['colors']['bg'] : '#FFFFFF'; // $config-global--color-background-default;
  69. // Editor color palette.
  70. add_theme_support(
  71. 'editor-color-palette',
  72. array(
  73. array(
  74. 'name' => __( 'Primary', 'redhill' ),
  75. 'slug' => 'primary',
  76. 'color' => $primary,
  77. ),
  78. array(
  79. 'name' => __( 'Secondary', 'redhill' ),
  80. 'slug' => 'secondary',
  81. 'color' => $secondary,
  82. ),
  83. array(
  84. 'name' => __( 'Foreground', 'redhill' ),
  85. 'slug' => 'foreground',
  86. 'color' => $foreground,
  87. ),
  88. array(
  89. 'name' => __( 'Background', 'redhill' ),
  90. 'slug' => 'background',
  91. 'color' => $background,
  92. ),
  93. )
  94. );
  95. // Add child theme support for core custom logo.
  96. add_theme_support(
  97. 'custom-logo',
  98. array(
  99. 'height' => 120,
  100. 'width' => 100,
  101. 'flex-width' => true,
  102. 'flex-height' => true,
  103. 'header-text' => array( 'site-title', 'site-description' ),
  104. )
  105. );
  106. }
  107. endif;
  108. add_action( 'after_setup_theme', 'redhill_theme_setup', 12 );
  109. /**
  110. * Set the content width in pixels, based on the child-theme's design and stylesheet.
  111. *
  112. * Priority 0 to make it available to lower priority callbacks.
  113. *
  114. * @global int $content_width Content width.
  115. */
  116. function redhill_theme_content_width() {
  117. // This variable is intended to be overruled from themes.
  118. // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
  119. // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
  120. $GLOBALS['content_width'] = apply_filters( 'redhill_theme_content_width', 740 );
  121. }
  122. add_action( 'after_setup_theme', 'redhill_theme_content_width', 0 );
  123. /**
  124. * Enqueue scripts and styles.
  125. */
  126. function redhill_theme_scripts() {
  127. // dequeue parent styles
  128. wp_dequeue_style( 'varia-style' );
  129. // enqueue child styles
  130. wp_enqueue_style( 'redhill-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ));
  131. // enqueue child RTL styles
  132. wp_style_add_data( 'redhill-style', 'rtl', 'replace' );
  133. }
  134. add_action( 'wp_enqueue_scripts', 'redhill_theme_scripts', 99 );