Hi,
I managed to add the class only to my related posts titles via grid code:
add_filter('wp_grid_builder/the_content', [ 'WP_Typography', 'process' ] );
function prefix_register_block( $blocks ) {
// 'my_block' corresponds to the block slug.
$blocks['wpgb_custom_title'] = [
'name' => __( 'WPGB Custom Title', 'text-domain' ),
'render_callback' => 'prefix_my_block_render',
];
return $blocks;
}
add_filter( 'wp_grid_builder/blocks', 'prefix_register_block', 10, 1 );
// The render callback function allows to output content in cards.
function prefix_my_block_render() {
// Get current post, term, or user object.
$post = wpgb_get_post();
// Output the post title.
echo '<span class="noTypo">' . esc_html( $post->post_title ) . '</span>';
}
And the noTypo class is succesfully added, yet the titles are not dewidowed.
Screenshot of the HTML:
flameshot_screenshot
Something is amiss here… could you advise what could be wrong?
Because when I added the class previously with:
function add_notypo_to_title( $title ) {
return "<span class='noTypo'>$title</span>";
}
if (! is_admin() ) {
add_filter( 'the_title', 'add_notypo_to_title', 10, 1 );
}
the dewidowing worked just fine.
Is it something with the way the title is retrieved in my grid code?
Thanks in advance,
I hope you and your businesses are doing well,
have a nice weekend.