Pledge: Use pledge description for excerpt

This commit is contained in:
Kelly Dwan 2024-08-29 14:51:58 -04:00
parent 906a87588c
commit c7026ace3c
No known key found for this signature in database
GPG key ID: 8BA5575F3D11575D
2 changed files with 26 additions and 5 deletions

View file

@ -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.

View file

@ -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<span class="screen-reader-text"> %s</span>', 'wporg-5ftf' ),
get_the_title( $instance->context['postId'] )
);
return str_replace( '[MORE]', $more_text, $block_content );
}