Thank you for the pointer.
This one did the trick for me
function wrap_anchor_text_with_span( $content ) {
if ( ! is_admin() && preg_match( '~<a(.*?)>(.*?)</a>~', $content ) ) {
$content = preg_replace_callback( '~<a(.*?)>(.*?)</a>~', '_add_span', $content );
}
return $content;
}
add_filter('the_content', 'wrap_anchor_text_with_span', 10);
function _add_span( $matches ) {
if ( ! ( $title = strip_tags( $matches[2] ) ) ) { // If we only have an image inside the anchor
return '<a' . $matches[1] . '>' . $matches[2] . '</a>';
} else {
return '<a' . $matches[1] . ' class="roll"><span data-title="' . esc_attr( $title ) . '">' . $matches[2] . '</span></a>';
}
}
from here