1

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?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.