functions.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. <?php declare( strict_types = 1 ); ?>
  2. <?php
  3. /**
  4. * Child Theme Functions and definitions
  5. *
  6. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  7. *
  8. * @package WordPress
  9. * @subpackage Shawburn
  10. * @since 1.0.0
  11. */
  12. if ( ! function_exists( 'varia_default_colors' ) ) {
  13. function varia_default_colors() {
  14. return array(
  15. 'background' => '#FFFFFF',
  16. 'foreground' => '#444444',
  17. 'primary' => '#0C80A1',
  18. 'secondary' => '#D4401C',
  19. 'tertiary' => null,
  20. );
  21. }
  22. }
  23. if ( ! function_exists( 'shawburn_setup' ) ) :
  24. /**
  25. * Sets up theme defaults and registers support for various WordPress features.
  26. *
  27. * Note that this function is hooked into the after_setup_theme hook, which
  28. * runs before the init hook. The init hook is too late for some features, such
  29. * as indicating support for post thumbnails.
  30. */
  31. function shawburn_setup() {
  32. // Add child theme editor styles, compiled from `style-child-theme-editor.scss`.
  33. add_editor_style( 'style-editor.css' );
  34. // Add child theme editor font sizes to match Sass-map variables in `_config-child-theme-deep.scss`.
  35. add_theme_support(
  36. 'editor-font-sizes',
  37. array(
  38. array(
  39. 'name' => __( 'Small', 'shawburn' ),
  40. 'shortName' => __( 'S', 'shawburn' ),
  41. 'size' => 15,
  42. 'slug' => 'small',
  43. ),
  44. array(
  45. 'name' => __( 'Normal', 'shawburn' ),
  46. 'shortName' => __( 'M', 'shawburn' ),
  47. 'size' => 18,
  48. 'slug' => 'normal',
  49. ),
  50. array(
  51. 'name' => __( 'Large', 'shawburn' ),
  52. 'shortName' => __( 'L', 'shawburn' ),
  53. 'size' => 25.92,
  54. 'slug' => 'large',
  55. ),
  56. array(
  57. 'name' => __( 'Huge', 'shawburn' ),
  58. 'shortName' => __( 'XL', 'shawburn' ),
  59. 'size' => 31.104,
  60. 'slug' => 'huge',
  61. ),
  62. )
  63. );
  64. // Enable Full Site Editing
  65. add_theme_support( 'full-site-editing' );
  66. // Add support for link color control.
  67. add_theme_support( 'link-color' );
  68. }
  69. endif;
  70. add_action( 'after_setup_theme', 'shawburn_setup', 12 );
  71. /**
  72. * Filter the content_width in pixels, based on the child-theme's design and stylesheet.
  73. */
  74. function shawburn_content_width() {
  75. return 750;
  76. }
  77. add_action( 'after_setup_theme', 'shawburn_content_width' );
  78. /**
  79. * Add Google webfonts, if necessary
  80. *
  81. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  82. */
  83. function shawburn_fonts_url() {
  84. $fonts_url = '';
  85. /* translators: If there are characters in your language that are not supported
  86. * by PT Sans, translate this to 'off'. Do not translate into your own language.
  87. */
  88. $pt_sans = _x( 'on', 'PT Sans font: on or off', 'shawburn' );
  89. /* translators: If there are characters in your language that are not supported
  90. * by PT Serif, translate this to 'off'. Do not translate into your own language.
  91. */
  92. $pt_serif = _x( 'on', 'PT Serif font: on or off', 'shawburn' );
  93. if ( 'off' !== $pt_sans || 'off' !== $pt_serif ) {
  94. $font_families = array();
  95. if ( 'off' !== $pt_sans ) {
  96. $font_families[] = 'PT Sans:400,400i,700,700i';
  97. }
  98. if ( 'off' !== $pt_serif ) {
  99. $font_families[] = 'PT Serif:400,400i,700,700i';
  100. }
  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. );
  111. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  112. }
  113. return esc_url_raw( $fonts_url );
  114. }
  115. /**
  116. * Enqueue scripts and styles.
  117. */
  118. function shawburn_scripts() {
  119. // enqueue Google fonts
  120. wp_enqueue_style( 'shawburn-fonts', shawburn_fonts_url(), array(), null );
  121. // dequeue parent styles
  122. wp_dequeue_style( 'varia-style' );
  123. // enqueue child styles
  124. wp_enqueue_style( 'shawburn-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
  125. // enqueue child RTL styles
  126. wp_style_add_data( 'shawburn-style', 'rtl', 'replace' );
  127. }
  128. add_action( 'wp_enqueue_scripts', 'shawburn_scripts', 99 );
  129. /**
  130. * Enqueue theme styles for the block editor.
  131. */
  132. function shawburn_editor_styles() {
  133. // Enqueue Google fonts in the editor
  134. wp_enqueue_style( 'shawburn-editor-fonts', shawburn_fonts_url(), array(), null );
  135. }
  136. add_action( 'enqueue_block_editor_assets', 'shawburn_editor_styles' );