functions.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Spearhead Blocks functions and definitions
  4. *
  5. * @link https://developer.wordpress.org/themes/basics/theme-functions/
  6. *
  7. * @package Spearhead Blocks
  8. * @since Spearhead Blocks 1.0
  9. */
  10. if ( ! function_exists( 'spearhead_blocks_support' ) ) :
  11. /**
  12. * Sets up theme defaults and registers support for various WordPress features.
  13. *
  14. * @since Spearhead Blocks 1.0
  15. *
  16. * @return void
  17. */
  18. function spearhead_blocks_support() {
  19. // Enqueue editor styles.
  20. add_editor_style( 'style.css' );
  21. }
  22. endif;
  23. add_action( 'after_setup_theme', 'spearhead_blocks_support' );
  24. if ( ! function_exists( 'spearhead_blocks_styles' ) ) :
  25. /**
  26. * Enqueue styles.
  27. *
  28. * @since Spearhead Blocks 1.0
  29. *
  30. * @return void
  31. */
  32. function spearhead_blocks_styles() {
  33. // Register theme stylesheet.
  34. wp_register_style(
  35. 'spearhead_blocks-style',
  36. get_template_directory_uri() . '/style.css',
  37. array(),
  38. wp_get_theme()->get( 'Version' )
  39. );
  40. // Enqueue theme stylesheet.
  41. wp_enqueue_style( 'spearhead_blocks-style' );
  42. }
  43. endif;
  44. add_action( 'wp_enqueue_scripts', 'spearhead_blocks_styles' );
  45. require get_template_directory() . '/inc/fonts/custom-fonts.php';
  46. function spearhead_blocks_the_excerpt( $excerpt ) {
  47. $audio_block = '';
  48. if ( has_block( 'audio' ) ) {
  49. $post = get_post();
  50. $blocks = parse_blocks( $post->post_content );
  51. foreach ( $blocks as $block ) {
  52. if ( 'core/audio' === $block['blockName'] ) {
  53. $audio_block .= '<div class="excerpt-audio-block">' . wp_kses_post( $block['innerHTML'] ) . '</div>';
  54. break;
  55. }
  56. }
  57. }
  58. // For cases where the post excerpt is empty
  59. // (but the post might have content)
  60. if ( 0 === strlen( $excerpt ) ) {
  61. return $excerpt . $audio_block;
  62. }
  63. return $excerpt . $audio_block;
  64. }
  65. // Filter the excerpt
  66. add_filter( 'get_the_excerpt', 'spearhead_blocks_the_excerpt' );