最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin3浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论