functions.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 mayland
  9. * @since 1.0.0
  10. */
  11. if ( ! function_exists( 'mayland_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 mayland_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', 'mayland' ),
  28. 'shortName' => __( 'S', 'mayland' ),
  29. 'size' => 16.6,
  30. 'slug' => 'small',
  31. ),
  32. array(
  33. 'name' => __( 'Normal', 'mayland' ),
  34. 'shortName' => __( 'M', 'mayland' ),
  35. 'size' => 20,
  36. 'slug' => 'normal',
  37. ),
  38. array(
  39. 'name' => __( 'Large', 'mayland' ),
  40. 'shortName' => __( 'L', 'mayland' ),
  41. 'size' => 28.8,
  42. 'slug' => 'large',
  43. ),
  44. array(
  45. 'name' => __( 'Huge', 'mayland' ),
  46. 'shortName' => __( 'XL', 'mayland' ),
  47. 'size' => 34.56,
  48. 'slug' => 'huge',
  49. ),
  50. )
  51. );
  52. /*
  53. * Get customizer colors and add them to the editor color palettes
  54. *
  55. * - if the customizer color is empty, use the default
  56. */
  57. $colors_array = get_theme_mod('colors_manager'); // color annotations array()
  58. $background = $colors_array['colors']['bg']; // $config-global--color-background-default;
  59. $primary = $colors_array['colors']['link']; // $config-global--color-primary-default;
  60. $foreground = $colors_array['colors']['txt']; // $config-global--color-foreground-default;
  61. $secondary = $colors_array['colors']['fg1']; // $config-global--color-secondary-default;
  62. // Editor color palette.
  63. add_theme_support(
  64. 'editor-color-palette',
  65. array(
  66. array(
  67. 'name' => __( 'Primary', 'mayland' ),
  68. 'slug' => 'primary',
  69. 'color' => ! isset($primary) ? '#000000' : $primary,
  70. ),
  71. array(
  72. 'name' => __( 'Secondary', 'mayland' ),
  73. 'slug' => 'secondary',
  74. 'color' => ! isset($secondary) ? '#1a1a1a' : $secondary,
  75. ),
  76. array(
  77. 'name' => __( 'Foreground', 'mayland' ),
  78. 'slug' => 'foreground',
  79. 'color' => ! isset($foreground) ? '#010101' : $foreground,
  80. ),
  81. array(
  82. 'name' => __( 'Background', 'mayland' ),
  83. 'slug' => 'background',
  84. 'color' => ! isset($background) ? '#FFFFFF' : $background,
  85. ),
  86. )
  87. );
  88. }
  89. endif;
  90. add_action( 'after_setup_theme', 'mayland_setup', 12 );
  91. /**
  92. * Filter the content_width in pixels, based on the child-theme's design and stylesheet.
  93. */
  94. function mayland_content_width() {
  95. return 750;
  96. }
  97. add_filter( 'varia_content_width', 'mayland_content_width' );
  98. /**
  99. * Add Google webfonts, if necessary
  100. *
  101. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  102. */
  103. function mayland_fonts_url() {
  104. $fonts_url = '';
  105. /* Translators: If there are characters in your language that are not
  106. * supported by Poppins, translate this to 'off'. Do not translate
  107. * into your own language.
  108. */
  109. $poppins = esc_html_x( 'on', 'Poppins font: on or off', 'mayland' );
  110. if ( 'off' !== $poppins ) {
  111. $font_families = array();
  112. $font_families[] = 'Poppins:400,400i,600,600i';
  113. $query_args = array(
  114. 'family' => urlencode( implode( '|', $font_families ) ),
  115. 'subset' => urlencode( 'latin,latin-ext' ),
  116. );
  117. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  118. }
  119. return esc_url_raw( $fonts_url );
  120. }
  121. /**
  122. * Enqueue scripts and styles.
  123. */
  124. function mayland_scripts() {
  125. // enqueue Google fonts, if necessary
  126. wp_enqueue_style( 'mayland-fonts', mayland_fonts_url(), array(), null );
  127. // dequeue parent styles
  128. wp_dequeue_style( 'varia-style' );
  129. // enqueue child styles
  130. wp_enqueue_style('mayland-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ));
  131. // enqueue child RTL styles
  132. wp_style_add_data( 'mayland-style', 'rtl', 'replace' );
  133. }
  134. add_action( 'wp_enqueue_scripts', 'mayland_scripts', 99 );
  135. /**
  136. * Enqueue theme styles for the block editor.
  137. */
  138. function mayland_editor_styles() {
  139. // Enqueue Google fonts in the editor, if necessary
  140. wp_enqueue_style( 'mayland-editor-fonts', mayland_fonts_url(), array(), null );
  141. }
  142. add_action( 'enqueue_block_editor_assets', 'mayland_editor_styles' );