My current theme comments are displayed using following code.

         <ol class="comment-list">
            <?php
                wp_list_comments( array(
                    'style'      => 'ol',
                    'short_ping' => true,
                ) );
            ?>
        </ol>

I need to remove “a href” part.I mean their should not be linked to the comment author website.

I check wp_list_comments() from codex, but I could not find how to remove <a href part.

2 Answers
2

Deep down the function uses get_comment_author_link() to output the author name. That function is filterable. Inside the function it checks if the author has a URL and wraps the name in a link to it if it exists. We can use the get_comment_author_link filter to just output the name, and ignore the URL. This is pretty simple, since the callback for this filter gets the author name as one of its arguments, so we just need to pass it through untouched:

function wpse_284352_author_link( $author_link, $author ) {
    return $author;
}
add_filter( 'get_comment_author_link', 'wpse_284352_author_link', 10, 2 );

EDIT: It’s actually even simpler, the URL has its own filter, which means that can be filtered with one of WordPress’ built in functions in one line:

add_filter( 'get_comment_author_url', '__return_empty_string' );

Leave a Reply

Your email address will not be published. Required fields are marked *