functions.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 Stratford
  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' => '#74767e',
  17. 'primary' => '#2c313f',
  18. 'secondary' => '#3e69dc',
  19. 'tertiary' => '#DDDDDD',
  20. );
  21. }
  22. }
  23. if ( ! function_exists( 'stratford_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 stratford_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', 'stratford' ),
  40. 'shortName' => __( 'S', 'stratford' ),
  41. 'size' => 16.6,
  42. 'slug' => 'small',
  43. ),
  44. array(
  45. 'name' => __( 'Normal', 'stratford' ),
  46. 'shortName' => __( 'M', 'stratford' ),
  47. 'size' => 20,
  48. 'slug' => 'normal',
  49. ),
  50. array(
  51. 'name' => __( 'Large', 'stratford' ),
  52. 'shortName' => __( 'L', 'stratford' ),
  53. 'size' => 28.8,
  54. 'slug' => 'large',
  55. ),
  56. array(
  57. 'name' => __( 'Huge', 'stratford' ),
  58. 'shortName' => __( 'XL', 'stratford' ),
  59. 'size' => 34.56,
  60. 'slug' => 'huge',
  61. ),
  62. )
  63. );
  64. // Remove footer menu
  65. unregister_nav_menu( 'menu-2' );
  66. // Add support for link color control.
  67. add_theme_support( 'link-color' );
  68. }
  69. endif;
  70. add_action( 'after_setup_theme', 'stratford_setup', 12 );
  71. /**
  72. * Filter the content_width in pixels, based on the child-theme's design and stylesheet.
  73. */
  74. function stratford_content_width() {
  75. return 900;
  76. }
  77. add_filter( 'varia_content_width', 'stratford_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 stratford_fonts_url() {
  84. $fonts_url = '';
  85. /* Translators: If there are characters in your language that are not
  86. * supported by Poppins, translate this to 'off'. Do not translate
  87. * into your own language.
  88. */
  89. $poppins = esc_html_x( 'on', 'Poppins font: on or off', 'stratford' );
  90. /* Translators: If there are characters in your language that are not
  91. * supported by Lato, translate this to 'off'. Do not translate
  92. * into your own language.
  93. */
  94. $lato = esc_html_x( 'on', 'Lato font: on or off', 'stratford' );
  95. /* Translators: If there are characters in your language that are not
  96. * supported by Inconsolata, translate this to 'off'. Do not translate
  97. * into your own language.
  98. */
  99. $inconsolata = esc_html_x( 'on', 'Inconsolata font: on or off', 'stratford' );
  100. if ( 'off' !== $poppins || 'off' !== $lato || 'off' !== $inconsolata ) {
  101. $font_families = array();
  102. if ( 'off' !== $poppins ) {
  103. $font_families[] = 'Poppins:400,700';
  104. }
  105. if ( 'off' !== $lato ) {
  106. $font_families[] = 'Lato:400,700,400italic,700italic';
  107. }
  108. if ( 'off' !== $inconsolata ) {
  109. $font_families[] = 'Inconsolata:400,700';
  110. }
  111. /**
  112. * A filter to enable child themes to add/change/omit font families.
  113. *
  114. * @param array $font_families An array of font families to be imploded for the Google Font API
  115. */
  116. $font_families = apply_filters( 'included_google_font_families', $font_families );
  117. $query_args = array(
  118. 'family' => urlencode( implode( '|', $font_families ) ),
  119. 'subset' => urlencode( 'latin,latin-ext' ),
  120. );
  121. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  122. }
  123. return esc_url_raw( $fonts_url );
  124. }
  125. /**
  126. * Enqueue scripts and styles.
  127. */
  128. function stratford_scripts() {
  129. // enqueue Google fonts, if necessary
  130. wp_enqueue_style( 'stratford-fonts', stratford_fonts_url(), array(), null );
  131. // dequeue parent styles
  132. wp_dequeue_style( 'varia-style' );
  133. // enqueue child styles
  134. wp_enqueue_style( 'stratford-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
  135. // enqueue child RTL styles
  136. wp_style_add_data( 'stratford-style', 'rtl', 'replace' );
  137. if ( ! stratford_is_amp() ) {
  138. // enqueue header spacing JS.
  139. wp_enqueue_script( 'stratford-fixed-header-spacing', get_stylesheet_directory_uri() . '/js/fixed-header-spacing.js', array(), wp_get_theme()->get( 'Version' ), true );
  140. }
  141. }
  142. add_action( 'wp_enqueue_scripts', 'stratford_scripts', 99 );
  143. /**
  144. * Enqueue theme styles for the block editor.
  145. */
  146. function stratford_editor_styles() {
  147. // Enqueue Google fonts in the editor, if necessary
  148. wp_enqueue_style( 'stratford-editor-fonts', stratford_fonts_url(), array(), null );
  149. }
  150. add_action( 'enqueue_block_editor_assets', 'stratford_editor_styles' );
  151. /**
  152. * Checks whether the endpoint is AMP.
  153. */
  154. function stratford_is_amp() {
  155. return ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() );
  156. }