I get this filter working to add the data attribute:
add_filter( 'related_posts_by_taxonomy_post_thumbnail_link', 'rpbt_related_post_category_image', 10, 4 );
function rpbt_related_post_category_image( $image, $attr, $related, $args ) {
// Get the same image with the size 'medium'.
$image = wp_get_attachment_image( $attr['thumbnail_id'], 'medium', false, $attr['describedby'] );
// Create the link for the image
$image = "<a href='{$attr['permalink']}' title='{$attr['title']}' data-toggle='tooltip'>{$image}</a>";
return $image;
}
But the link has lost its title content (it showed up before the filter).
I guess i have to modify $attr['title']…?
In summary, this code in the filter:
$image = "<a href='{$attr['permalink']}' title='{$attr['title']}' data-toggle='tooltip'>{$image}</a>";
Renders this in HTML:
<a href="https://domain.com" title="" data-toggle="tooltip" data-original-title="">
So, no title content is rendered and i get a second data-original-title coming from i don’t know where…
I’d like to get this:
<a href="https://domain.com" title=My title content" data-toggle="tooltip">
Any tip please?
My Bootstrap Tooltips finally work, i obtained the related posts title with get_the_title( $post->ID )
The whole filter code:
add_filter('related_posts_by_taxonomy_post_thumbnail_link','add_bootstrap_tooltip_to_related_posts_thumbnails', 10,4);
function add_bootstrap_tooltip_to_related_posts_thumbnails( $link, $attr, $post, $args ) {
$related_post_title = get_the_title( $post->ID );
// Link for post thumbnails
$link = "<a href='{$attr['permalink']}' title='{$related_post_title}' data-toggle='tooltip'>{$attr['thumbnail']}</a>";
return $link;
}
Hi studioavanti
I’m sorry I’ve missed this post somehow. I’m glad you found a solution yourself 🙂
I think it sould also work if you used this for the title:
title='{$attr['title_attr']}'
Hi @keesiemeijer,
No prob, thanks for your hint.
It seems the option was already available in RPBT and maybe i missed it in the rich plugin documentation: simplest than a custom filter indeed.