functions.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 Rockfield
  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' => '#222222',
  17. 'secondary' => '#116821',
  18. 'tertiary' => '#E0E0E0',
  19. );
  20. }
  21. }
  22. if ( ! function_exists( 'rockfield_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 rockfield_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', 'rockfield' ),
  39. 'shortName' => __( 'S', 'rockfield' ),
  40. 'size' => 15,
  41. 'slug' => 'small',
  42. ),
  43. array(
  44. 'name' => __( 'Normal', 'rockfield' ),
  45. 'shortName' => __( 'M', 'rockfield' ),
  46. 'size' => 18,
  47. 'slug' => 'normal',
  48. ),
  49. array(
  50. 'name' => __( 'Large', 'rockfield' ),
  51. 'shortName' => __( 'L', 'rockfield' ),
  52. 'size' => 25.92,
  53. 'slug' => 'large',
  54. ),
  55. array(
  56. 'name' => __( 'Huge', 'rockfield' ),
  57. 'shortName' => __( 'XL', 'rockfield' ),
  58. 'size' => 31.104,
  59. 'slug' => 'huge',
  60. ),
  61. )
  62. );
  63. // Add support for link color control.
  64. add_theme_support( 'link-color' );
  65. }
  66. endif;
  67. add_action( 'after_setup_theme', 'rockfield_setup', 12 );
  68. /**
  69. * Filter the content_width in pixels, based on the child-theme's design and stylesheet.
  70. */
  71. function rockfield_content_width() {
  72. return 750;
  73. }
  74. add_filter( 'varia_content_width', 'rockfield_content_width' );
  75. /**
  76. * Add Google webfonts, if necessary
  77. *
  78. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  79. */
  80. function rockfield_fonts_url() {
  81. $fonts_url = '';
  82. /* Translators: If there are characters in your language that are not
  83. * supported by Raleway, translate this to 'off'. Do not translate
  84. * into your own language.
  85. */
  86. $raleway = esc_html_x( 'on', 'Raleway font: on or off', 'rockfield' );
  87. /* Translators: If there are characters in your language that are not
  88. * supported by Lora, translate this to 'off'. Do not translate
  89. * into your own language.
  90. */
  91. $lora = esc_html_x( 'on', 'Lora font: on or off', 'rockfield' );
  92. if ( 'off' !== $raleway || 'off' !== $lora ) {
  93. $font_families = array();
  94. if ( 'off' !== $raleway ) {
  95. $font_families[] = 'Raleway:400,400i,700,700i';
  96. }
  97. if ( 'off' !== $lora ) {
  98. $font_families[] = 'Lora: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 rockfield_scripts() {
  118. // enqueue Google fonts
  119. wp_enqueue_style( 'rockfield-fonts', rockfield_fonts_url(), array(), null );
  120. // dequeue parent styles
  121. wp_dequeue_style( 'varia-style' );
  122. // enqueue child styles
  123. wp_enqueue_style( 'rockfield-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
  124. // enqueue child RTL styles
  125. wp_style_add_data( 'rockfield-style', 'rtl', 'replace' );
  126. if ( ! rockfield_is_amp() ) {
  127. // enqueue header spacing JS.
  128. wp_enqueue_script( 'rockfield-fixed-header-spacing', get_stylesheet_directory_uri() . '/js/fixed-header-spacing.js', array(), wp_get_theme()->get( 'Version' ), true );
  129. }
  130. }
  131. add_action( 'wp_enqueue_scripts', 'rockfield_scripts', 99 );
  132. /**
  133. * Enqueue theme styles for the block editor.
  134. */
  135. function rockfield_editor_styles() {
  136. // Enqueue Google fonts in the editor
  137. wp_enqueue_style( 'rockfield-editor-fonts', rockfield_fonts_url(), array(), null );
  138. }
  139. add_action( 'enqueue_block_editor_assets', 'rockfield_editor_styles' );
  140. /**
  141. * Checks whether the endpoint is AMP.
  142. */
  143. function rockfield_is_amp() {
  144. return ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() );
  145. }