filters - How to link the whole list item in Gutenberg's latest posts block?

I am using a Gutenberg's 'Latest Posts' block on my front page. Featured image display and grid layout ar

I am using a Gutenberg's 'Latest Posts' block on my front page. Featured image display and grid layout are enabled in the block settings.

By default, only the post title is linked to the actual post. However, users are tempted to click on the post image or even somwhere on the excerpt in order to get to the respective article.

So, how can I apply a filter to the block output, which adds a link to the whole list item rather than just the post title? I'm looking for something like this:

function my_post_item( $post ){
  
  // Fetch the link
  $post_url = get_permalink( $post );
  // Wrap anchor tag around list item's content
  $list_item = '<li><a href="' . $post_url . '">';
  $list_item .= $default_latest_post_item_content;
  $list_item .= '</a></li>';

  return $list_item;
   
}
add_filter( 'gutenberg_latest_post_item', 'my_post_item' );

Any ideas?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742275463a4413503.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信