I have the following code in my comments.php

  <div class="reply">
     <?php comment_reply_link(array_merge( $args, array('depth' => $depth, 'max_depth' => $args['max_depth']))) ?>

I've tried to put the following filter, but it breaks the layout (it adds 2 lines of text/url):

function additemproptocommentreplylink( $atts, $item, $args ) {
    $atts['itemprop'] = 'replyToUrl';
    return $atts;
add_filter('comment_reply_link', 'additemproptocommentreplylink', 3, 10);

Can someone suggest how I can add that itemprop to the reply link?



You could instead try the following replacement:

 * Add itemprop attribute to the comment reply link

add_filter('comment_reply_link', function( $html )
    if( false === stripos( $html, 'itemprop="' ) )
        $html = str_ireplace( '<a ', '<a itemprop="replyToUrl" ', $html ); 
    return $html;
}, 99 );

through the comment_reply_link filter. The HTML generation, of the comment reply link, only supports a given set of attributes and itemprop is not among them. That's why we try the replacement here instead.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.