functions.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 if Gutenberg is activated (otherwise the __experimentalMenuLocation attribute isn't available)
  24. if ( defined( 'IS_GUTENBERG_PLUGIN' ) ) {
  25. register_nav_menus(
  26. array(
  27. 'primary' => __( 'Primary Navigation', 'blockbase' ),
  28. 'social' => __( 'Social Navigation', 'blockbase' ),
  29. )
  30. );
  31. }
  32. add_filter(
  33. 'block_editor_settings_all',
  34. function( $settings ) {
  35. $settings['defaultBlockTemplate'] = '<!-- wp:group {"layout":{"inherit":true}} --><div class="wp-block-group"><!-- wp:post-content /--></div><!-- /wp:group -->';
  36. return $settings;
  37. }
  38. );
  39. // Add support for core custom logo.
  40. add_theme_support(
  41. 'custom-logo',
  42. array(
  43. 'height' => 192,
  44. 'width' => 192,
  45. 'flex-width' => true,
  46. 'flex-height' => true,
  47. )
  48. );
  49. }
  50. endif;
  51. add_action( 'after_setup_theme', 'blockbase_support', 9 );
  52. /**
  53. *
  54. * Enqueue scripts and styles.
  55. */
  56. function blockbase_editor_styles() {
  57. // Add the child theme CSS if it exists.
  58. if ( file_exists( get_stylesheet_directory() . '/assets/theme.css' ) ) {
  59. add_editor_style(
  60. '/assets/theme.css'
  61. );
  62. }
  63. }
  64. add_action( 'admin_init', 'blockbase_editor_styles' );
  65. /**
  66. *
  67. * Enqueue scripts and styles.
  68. */
  69. function blockbase_scripts() {
  70. wp_enqueue_style( 'blockbase-ponyfill', get_template_directory_uri() . '/assets/ponyfill.css', array(), wp_get_theme()->get( 'Version' ) );
  71. // Add the child theme CSS if it exists.
  72. if ( file_exists( get_stylesheet_directory() . '/assets/theme.css' ) ) {
  73. wp_enqueue_style( 'blockbase-child-styles', get_stylesheet_directory_uri() . '/assets/theme.css', array( 'blockbase-ponyfill' ), wp_get_theme()->get( 'Version' ) );
  74. }
  75. }
  76. add_action( 'wp_enqueue_scripts', 'blockbase_scripts' );
  77. /**
  78. * Customize Global Styles
  79. */
  80. if ( class_exists( 'WP_Theme_JSON_Resolver_Gutenberg' ) ) {
  81. require get_template_directory() . '/inc/customizer/wp-customize-colors.php';
  82. require get_template_directory() . '/inc/social-navigation.php';
  83. }
  84. require get_template_directory() . '/inc/fonts/custom-fonts.php';
  85. // Force menus to reload
  86. add_action(
  87. 'customize_controls_enqueue_scripts',
  88. static function () {
  89. wp_enqueue_script(
  90. 'wp-customize-nav-menu-refresh',
  91. get_template_directory_uri() . '/inc/customizer/wp-customize-nav-menu-refresh.js',
  92. array( 'customize-nav-menus' ),
  93. wp_get_theme()->get( 'Version' ),
  94. true
  95. );
  96. }
  97. );
  98. /**
  99. * Disable the fallback for the core/navigation block.
  100. */
  101. function blockbase_core_navigation_render_fallback() {
  102. return null;
  103. }
  104. add_filter( 'block_core_navigation_render_fallback', 'blockbase_core_navigation_render_fallback' );
  105. /**
  106. * Block Patterns.
  107. */
  108. require get_template_directory() . '/inc/block-patterns.php';
  109. // Add the child theme patterns if they exist.
  110. if ( file_exists( get_stylesheet_directory() . '/inc/block-patterns.php' ) ) {
  111. require_once get_stylesheet_directory() . '/inc/block-patterns.php';
  112. }