functions.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 Shawburn
  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' => '#444444',
  16. 'primary' => '#0C80A1',
  17. 'secondary' => '#D4401C',
  18. 'tertiary' => null,
  19. );
  20. }
  21. }
  22. if ( ! function_exists( 'shawburn_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 shawburn_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', 'shawburn' ),
  39. 'shortName' => __( 'S', 'shawburn' ),
  40. 'size' => 15,
  41. 'slug' => 'small',
  42. ),
  43. array(
  44. 'name' => __( 'Normal', 'shawburn' ),
  45. 'shortName' => __( 'M', 'shawburn' ),
  46. 'size' => 18,
  47. 'slug' => 'normal',
  48. ),
  49. array(
  50. 'name' => __( 'Large', 'shawburn' ),
  51. 'shortName' => __( 'L', 'shawburn' ),
  52. 'size' => 25.92,
  53. 'slug' => 'large',
  54. ),
  55. array(
  56. 'name' => __( 'Huge', 'shawburn' ),
  57. 'shortName' => __( 'XL', 'shawburn' ),
  58. 'size' => 31.104,
  59. 'slug' => 'huge',
  60. ),
  61. )
  62. );
  63. // Enable Full Site Editing
  64. add_theme_support( 'full-site-editing' );
  65. // Add support for experimental link color via Gutenberg: https://github.com/WordPress/gutenberg/blob/master/docs/designers-developers/developers/themes/theme-support.md
  66. add_theme_support( 'experimental-link-color' );
  67. }
  68. endif;
  69. add_action( 'after_setup_theme', 'shawburn_setup', 12 );
  70. /**
  71. * Filter the content_width in pixels, based on the child-theme's design and stylesheet.
  72. */
  73. function shawburn_content_width() {
  74. return 750;
  75. }
  76. add_action( 'after_setup_theme', 'shawburn_content_width' );
  77. /**
  78. * Add Google webfonts, if necessary
  79. *
  80. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  81. */
  82. function shawburn_fonts_url() {
  83. $fonts_url = '';
  84. /* translators: If there are characters in your language that are not supported
  85. * by PT Sans, translate this to 'off'. Do not translate into your own language.
  86. */
  87. $pt_sans = _x( 'on', 'PT Sans font: on or off', 'shawburn' );
  88. /* translators: If there are characters in your language that are not supported
  89. * by PT Serif, translate this to 'off'. Do not translate into your own language.
  90. */
  91. $pt_serif = _x( 'on', 'PT Serif font: on or off', 'shawburn' );
  92. if ( 'off' !== $pt_sans || 'off' !== $pt_serif ) {
  93. $font_families = array();
  94. if ( 'off' !== $pt_sans ) {
  95. $font_families[] = 'PT Sans:400,400i,700,700i';
  96. }
  97. if ( 'off' !== $pt_serif ) {
  98. $font_families[] = 'PT Serif:400,400i,700,700i';
  99. }
  100. /**
  101. * A filter to enable child themes to add/change/omit font families.
  102. *
  103. * @param array $font_families An array of font families to be imploded for the Google Font API
  104. */
  105. $font_families = apply_filters( 'included_google_font_families', $font_families );
  106. $query_args = array(
  107. 'family' => urlencode( implode( '|', $font_families ) ),
  108. 'subset' => urlencode( 'latin,latin-ext' ),
  109. );
  110. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  111. }
  112. return esc_url_raw( $fonts_url );
  113. }
  114. /**
  115. * Enqueue scripts and styles.
  116. */
  117. function shawburn_scripts() {
  118. // enqueue Google fonts
  119. wp_enqueue_style( 'shawburn-fonts', shawburn_fonts_url(), array(), null );
  120. // dequeue parent styles
  121. wp_dequeue_style( 'varia-style' );
  122. // enqueue child styles
  123. wp_enqueue_style( 'shawburn-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
  124. // enqueue child RTL styles
  125. wp_style_add_data( 'shawburn-style', 'rtl', 'replace' );
  126. }
  127. add_action( 'wp_enqueue_scripts', 'shawburn_scripts', 99 );
  128. /**
  129. * Enqueue theme styles for the block editor.
  130. */
  131. function shawburn_editor_styles() {
  132. // Enqueue Google fonts in the editor
  133. wp_enqueue_style( 'shawburn-editor-fonts', shawburn_fonts_url(), array(), null );
  134. }
  135. add_action( 'enqueue_block_editor_assets', 'shawburn_editor_styles' );