From c7026ace3c0b4165afedc16e34d9093399794bbe Mon Sep 17 00:00:00 2001 From: Kelly Dwan Date: Thu, 29 Aug 2024 14:51:58 -0400 Subject: [PATCH] Pledge: Use pledge description for excerpt --- themes/wporg-5ftf-2024/functions.php | 9 ++++----- themes/wporg-5ftf-2024/inc/block-config.php | 22 +++++++++++++++++++++ 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/themes/wporg-5ftf-2024/functions.php b/themes/wporg-5ftf-2024/functions.php index 0b7b16f..cf859af 100644 --- a/themes/wporg-5ftf-2024/functions.php +++ b/themes/wporg-5ftf-2024/functions.php @@ -17,7 +17,8 @@ require_once __DIR__ . '/src/pledge-teams/index.php'; * Actions and filters. */ add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_assets' ); -add_filter( 'the_content', __NAMESPACE__ . '\inject_pledge_content' ); +add_filter( 'the_content', __NAMESPACE__ . '\inject_pledge_content', 1 ); +add_filter( 'get_the_excerpt', __NAMESPACE__ . '\inject_pledge_content', 1 ); add_filter( 'search_template_hierarchy', __NAMESPACE__ . '\use_archive_template' ); /** @@ -54,11 +55,9 @@ function inject_pledge_content( $content ) { return $content; } - remove_filter( 'the_content', __NAMESPACE__ . '\inject_pledge_content' ); - $data = get_pledge_meta( get_the_ID() ); - $content = apply_filters( 'the_content', $data['org-description'] ); - return $content; + return $data['org-description']; +} /** * Switch to the archive.html template on search results. diff --git a/themes/wporg-5ftf-2024/inc/block-config.php b/themes/wporg-5ftf-2024/inc/block-config.php index 27041aa..5290a32 100644 --- a/themes/wporg-5ftf-2024/inc/block-config.php +++ b/themes/wporg-5ftf-2024/inc/block-config.php @@ -5,7 +5,11 @@ namespace WordPressDotOrg\Theme\FiveForTheFuture_2024\Block_Config; +/** + * Actions and filters. + */ add_filter( 'wporg_block_navigation_menus', __NAMESPACE__ . '\add_site_navigation_menus' ); +add_filter( 'render_block_core/post-excerpt', __NAMESPACE__ . '\inject_excerpt_more_link', 10, 3 ); /** * Provide a list of local navigation menus. @@ -45,3 +49,21 @@ function add_site_navigation_menus( $menus ) { 'main' => $menu, ); } + +/** + * Update the excerpt block content, replacing the placeholder string with + * dynamic text including the pledge title for unique link text. + * + * @param string $block_content The block content. + * @param array $block The full block, including name and attributes. + * @param WP_Block $instance The block instance. + * + * @return string Updated block content. + */ +function inject_excerpt_more_link( $block_content, $block, $instance ) { + $more_text = sprintf( + __( 'Continue reading %s', 'wporg-5ftf' ), + get_the_title( $instance->context['postId'] ) + ); + return str_replace( '[MORE]', $more_text, $block_content ); +}