functions.php 5.3 KB

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