functions.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. if ( ! function_exists( 'blockbase_support' ) ) :
  3. function blockbase_support() {
  4. // Make theme available for translation.
  5. load_theme_textdomain( 'blockbase' );
  6. if ( ! 'blockbase' === wp_get_theme()->get( 'TextDomain' ) ) {
  7. load_theme_textdomain( wp_get_theme()->get( 'TextDomain' ) );
  8. }
  9. // Alignwide and alignfull classes in the block editor.
  10. add_theme_support( 'align-wide' );
  11. // Add support for experimental link color control.
  12. add_theme_support( 'experimental-link-color' );
  13. // Add support for responsive embedded content.
  14. // https://github.com/WordPress/gutenberg/issues/26901
  15. add_theme_support( 'responsive-embeds' );
  16. // Add support for editor styles.
  17. add_theme_support( 'editor-styles' );
  18. // Add support for post thumbnails.
  19. add_theme_support( 'post-thumbnails' );
  20. // Experimental support for adding blocks inside nav menus
  21. add_theme_support( 'block-nav-menus' );
  22. // Enqueue editor styles.
  23. add_editor_style(
  24. array(
  25. '/assets/ponyfill.css',
  26. )
  27. );
  28. // Register two nav menus if Gutenberg is activated (otherwise the __experimentalMenuLocation attribute isn't available)
  29. if ( defined( 'IS_GUTENBERG_PLUGIN' ) ) {
  30. register_nav_menus(
  31. array(
  32. 'primary' => __( 'Primary Navigation', 'blockbase' ),
  33. 'social' => __( 'Social Navigation', 'blockbase' ),
  34. )
  35. );
  36. }
  37. add_filter(
  38. 'block_editor_settings_all',
  39. function( $settings ) {
  40. $settings['defaultBlockTemplate'] = '<!-- wp:group {"layout":{"inherit":true}} --><div class="wp-block-group"><!-- wp:post-content /--></div><!-- /wp:group -->';
  41. return $settings;
  42. }
  43. );
  44. // Add support for core custom logo.
  45. add_theme_support(
  46. 'custom-logo',
  47. array(
  48. 'height' => 192,
  49. 'width' => 192,
  50. 'flex-width' => true,
  51. 'flex-height' => true,
  52. )
  53. );
  54. }
  55. endif;
  56. add_action( 'after_setup_theme', 'blockbase_support', 9 );
  57. /**
  58. *
  59. * Enqueue scripts and styles.
  60. */
  61. function blockbase_editor_styles() {
  62. // Add the child theme CSS if it exists.
  63. if ( file_exists( get_stylesheet_directory() . '/assets/theme.css' ) ) {
  64. add_editor_style(
  65. '/assets/theme.css'
  66. );
  67. }
  68. }
  69. add_action( 'admin_init', 'blockbase_editor_styles' );
  70. /**
  71. *
  72. * Enqueue scripts and styles.
  73. */
  74. function blockbase_scripts() {
  75. wp_enqueue_style( 'blockbase-ponyfill', get_template_directory_uri() . '/assets/ponyfill.css', array(), wp_get_theme()->get( 'Version' ) );
  76. // Add the child theme CSS if it exists.
  77. if ( file_exists( get_stylesheet_directory() . '/assets/theme.css' ) ) {
  78. wp_enqueue_style( 'blockbase-child-styles', get_stylesheet_directory_uri() . '/assets/theme.css', array( 'blockbase-ponyfill' ), wp_get_theme()->get( 'Version' ) );
  79. }
  80. }
  81. add_action( 'wp_enqueue_scripts', 'blockbase_scripts' );
  82. /**
  83. * Customize Global Styles
  84. */
  85. if ( class_exists( 'WP_Theme_JSON_Resolver_Gutenberg' ) ) {
  86. require get_template_directory() . '/inc/customizer/wp-customize-colors.php';
  87. require get_template_directory() . '/inc/social-navigation.php';
  88. }
  89. require get_template_directory() . '/inc/fonts/custom-fonts.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. * Block Patterns.
  105. */
  106. require get_template_directory() . '/inc/block-patterns.php';
  107. // Add the child theme patterns if they exist.
  108. if ( file_exists( get_stylesheet_directory() . '/inc/block-patterns.php' ) ) {
  109. require_once get_stylesheet_directory() . '/inc/block-patterns.php';
  110. }