functions.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. if ( ! function_exists( 'blockbase_support' ) ) :
  3. function blockbase_support() {
  4. // Alignwide and alignfull classes in the block editor.
  5. add_theme_support( 'align-wide' );
  6. // Add support for experimental link color control.
  7. add_theme_support( 'experimental-link-color' );
  8. // Add support for responsive embedded content.
  9. // https://github.com/WordPress/gutenberg/issues/26901
  10. add_theme_support( 'responsive-embeds' );
  11. // Add support for editor styles.
  12. add_theme_support( 'editor-styles' );
  13. // Add support for post thumbnails.
  14. add_theme_support( 'post-thumbnails' );
  15. // Experimental support for adding blocks inside nav menus
  16. add_theme_support( 'block-nav-menus' );
  17. // Enqueue editor styles.
  18. add_editor_style(
  19. array(
  20. '/assets/ponyfill.css',
  21. )
  22. );
  23. // Register two nav menus
  24. register_nav_menus(
  25. array(
  26. 'primary' => __( 'Primary Navigation', 'blockbase' ),
  27. 'social' => __( 'Social Navigation', 'blockbase' ),
  28. )
  29. );
  30. add_filter(
  31. 'block_editor_settings_all',
  32. function( $settings ) {
  33. $settings['defaultBlockTemplate'] = '<!-- wp:group {"layout":{"inherit":true}} --><div class="wp-block-group"><!-- wp:post-content /--></div><!-- /wp:group -->';
  34. return $settings;
  35. }
  36. );
  37. // Add support for core custom logo.
  38. add_theme_support(
  39. 'custom-logo',
  40. array(
  41. 'height' => 192,
  42. 'width' => 192,
  43. 'flex-width' => true,
  44. 'flex-height' => true,
  45. )
  46. );
  47. }
  48. endif;
  49. add_action( 'after_setup_theme', 'blockbase_support', 9 );
  50. /**
  51. *
  52. * Enqueue scripts and styles.
  53. */
  54. function blockbase_editor_styles() {
  55. // Add the child theme CSS if it exists.
  56. if ( file_exists( get_stylesheet_directory() . '/assets/theme.css' ) ) {
  57. add_editor_style(
  58. '/assets/theme.css'
  59. );
  60. }
  61. }
  62. add_action( 'admin_init', 'blockbase_editor_styles' );
  63. /**
  64. *
  65. * Enqueue scripts and styles.
  66. */
  67. function blockbase_scripts() {
  68. wp_enqueue_style( 'blockbase-ponyfill', get_template_directory_uri() . '/assets/ponyfill.css', array(), wp_get_theme()->get( 'Version' ) );
  69. // Add the child theme CSS if it exists.
  70. if ( file_exists( get_stylesheet_directory() . '/assets/theme.css' ) ) {
  71. wp_enqueue_style( 'blockbase-child-styles', get_stylesheet_directory_uri() . '/assets/theme.css', array( 'blockbase-ponyfill' ), wp_get_theme()->get( 'Version' ) );
  72. }
  73. }
  74. add_action( 'wp_enqueue_scripts', 'blockbase_scripts' );
  75. /**
  76. * Customize Global Styles
  77. */
  78. if ( class_exists( 'WP_Theme_JSON_Resolver_Gutenberg' ) ) {
  79. require get_template_directory() . '/inc/customizer/wp-customize-colors.php';
  80. require get_template_directory() . '/inc/customizer/wp-customize-color-palettes.php';
  81. require get_template_directory() . '/inc/social-navigation.php';
  82. }
  83. // Font Management
  84. require get_template_directory() . '/inc/fonts/wptt-webfont-loader.php';
  85. require get_template_directory() . '/inc/fonts/custom-fonts.php';
  86. // Font settings deprecation message
  87. require get_template_directory() . '/inc/customizer/wp-customize-fonts.php';
  88. // Font Migration
  89. require get_template_directory() . '/inc/fonts/custom-font-migration.php';
  90. // Force menus to reload
  91. add_action(
  92. 'customize_controls_enqueue_scripts',
  93. static function () {
  94. wp_enqueue_script(
  95. 'wp-customize-nav-menu-refresh',
  96. get_template_directory_uri() . '/inc/customizer/wp-customize-nav-menu-refresh.js',
  97. array( 'customize-nav-menus' ),
  98. wp_get_theme()->get( 'Version' ),
  99. true
  100. );
  101. }
  102. );
  103. /**
  104. * Disable the fallback for the core/navigation block.
  105. */
  106. function blockbase_core_navigation_render_fallback() {
  107. return null;
  108. }
  109. add_filter( 'block_core_navigation_render_fallback', 'blockbase_core_navigation_render_fallback' );
  110. /**
  111. * Block Patterns.
  112. */
  113. require get_template_directory() . '/inc/block-patterns.php';
  114. // Add the child theme patterns if they exist.
  115. if ( file_exists( get_stylesheet_directory() . '/inc/block-patterns.php' ) ) {
  116. require_once get_stylesheet_directory() . '/inc/block-patterns.php';
  117. }