Hi @glenlipka – may I ask where you got that code? If it’s older, it may not be compatible with the version of jQuery that ships with core.
Rather than JavaScript, I borrowed a PHP function from “solution 1” found here, which worked perfectly on my test site. All I had to do to get it working was change the class name to match Twenty Twenty-Two, i.e. wp-block-post-excerpt__excerpt
I popped the code in a plugin file called clickable-excerpts.php and it worked perfectly:
<?php
/*
Plugin Name: Wrap excerpt in a link
Description: Adds a link around post excerpts
Version: 1
URL: https://wordpress.org/support/topic/make-post-excerpt-clickable/?view=all
*/
function clickable_excerpt( $excerpt ) {
return '<a href="'. get_the_permalink() .'" class="wp-block-post-excerpt__excerpt">'. $excerpt .'</a>';
}
add_filter( 'get_the_excerpt', 'clickable_excerpt' );
If you want to remove the default formatting (i.e. colour & underline, etc.) you can add some custom CSS as well.
Let me know how it goes!
I ended up going a different route. I added in a cover block wrapping the H1 and Post Excerpt using the Stretch Link property. It would be smart for the theme editors to make this property available on the group block. Or just give a property to the post excerpt block called “Link to post”.
Details here: https://commadot.com/wordpress-twenty-twenty-two-part-2/
Thanks for sharing your workaround! I went ahead and put it an enhancement request for your idea:
https://github.com/WordPress/gutenberg/issues/42935
Feel free to share other enhancements or report bugs there in the future. You have some great insights and you’re very welcome to share them directly with the folks working on the editor!
I’ll mark this as resolved for now but feel free to post again if you need help with something else.