functions.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 Morden
  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' => '#303030',
  16. 'primary' => '#CD2220',
  17. 'secondary' => '#007AB7',
  18. 'tertiary' => null,
  19. );
  20. }
  21. }
  22. if ( ! function_exists( 'morden_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 morden_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', 'morden' ),
  39. 'shortName' => __( 'S', 'morden' ),
  40. 'size' => 16.6,
  41. 'slug' => 'small',
  42. ),
  43. array(
  44. 'name' => __( 'Normal', 'morden' ),
  45. 'shortName' => __( 'M', 'morden' ),
  46. 'size' => 20,
  47. 'slug' => 'normal',
  48. ),
  49. array(
  50. 'name' => __( 'Large', 'morden' ),
  51. 'shortName' => __( 'L', 'morden' ),
  52. 'size' => 26.45,
  53. 'slug' => 'large',
  54. ),
  55. array(
  56. 'name' => __( 'Huge', 'morden' ),
  57. 'shortName' => __( 'XL', 'morden' ),
  58. 'size' => 30.4174,
  59. 'slug' => 'huge',
  60. ),
  61. )
  62. );
  63. // Setup nav on side toggle support.
  64. if ( function_exists( 'varia_mobile_nav_on_side_setup' ) ) {
  65. varia_mobile_nav_on_side_setup();
  66. }
  67. }
  68. endif;
  69. add_action( 'after_setup_theme', 'morden_setup', 12 );
  70. /**
  71. * Set the content width in pixels, based on the child-theme's design and stylesheet.
  72. *
  73. * Priority 0 to make it available to lower priority callbacks.
  74. *
  75. * @global int $content_width Content width.
  76. */
  77. function morden_content_width() {
  78. // This variable is intended to be overruled from themes.
  79. // Open WPCS issue: {@link https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/issues/1043}.
  80. // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
  81. $GLOBALS['content_width'] = apply_filters( 'morden_content_width', 740 );
  82. }
  83. add_action( 'after_setup_theme', 'morden_content_width', 0 );
  84. /**
  85. * Add Google webfonts, if necessary
  86. *
  87. * - See: http://themeshaper.com/2014/08/13/how-to-add-google-fonts-to-wordpress-themes/
  88. */
  89. function morden_fonts_url() {
  90. $fonts_url = '';
  91. /* Translators: If there are characters in your language that are not
  92. * supported by Noto Sans, translate this to 'off'. Do not translate
  93. * into your own language.
  94. */
  95. $notosans = esc_html_x( 'on', 'Noto Sans font: on or off', 'morden' );
  96. if ( 'off' !== $notosans ) {
  97. $font_families = array();
  98. $font_families[] = 'Noto Sans:400,400i,700,700i';
  99. $query_args = array(
  100. 'family' => urlencode( implode( '|', $font_families ) ),
  101. 'subset' => urlencode( 'latin,latin-ext' ),
  102. );
  103. $fonts_url = add_query_arg( $query_args, 'https://fonts.googleapis.com/css' );
  104. }
  105. return esc_url_raw( $fonts_url );
  106. }
  107. /**
  108. * Enqueue scripts and styles.
  109. */
  110. function morden_scripts() {
  111. // enqueue Google fonts
  112. wp_enqueue_style( 'morden-fonts', morden_fonts_url(), array(), null );
  113. // dequeue parent styles
  114. wp_dequeue_style( 'varia-style' );
  115. // enqueue child styles
  116. wp_enqueue_style( 'morden-style', get_stylesheet_uri(), array(), wp_get_theme()->get( 'Version' ) );
  117. // enqueue child RTL styles
  118. wp_style_add_data( 'morden-style', 'rtl', 'replace' );
  119. }
  120. add_action( 'wp_enqueue_scripts', 'morden_scripts', 99 );
  121. /**
  122. * Enqueue theme styles for the block editor.
  123. */
  124. function morden_editor_styles() {
  125. // enqueue Google fonts in the editor
  126. wp_enqueue_style( 'morden-editor-fonts', morden_fonts_url(), array(), null );
  127. }
  128. add_action( 'enqueue_block_editor_assets', 'morden_editor_styles' );