0

I need to remove links to the comments section from every post and page on the site. Links to comments look like this:

These links appear:

  1. In the post's byline as a speech bubble icon with the number of comments, hyperlinked to the comments section. https://example.com/post-title/#comments

  2. In the comments section itself, where each comment's date is hyperlinked to the individual post's URL, such as https://example.com/post-title/#comment-1234

I am using a child theme of a third-party theme called Newsmatic.

1 Answer 1

0

Add this to your theme functions file:

// This will occur when the comment is posted
function plc_comment_post( $incoming_comment ) {
 
    // convert everything in a comment to display literally
    $incoming_comment['comment_content'] = htmlspecialchars($incoming_comment['comment_content']);
 
    // the one exception is single quotes, which cannot be #039; because WordPress marks it as spam
    $incoming_comment['comment_content'] = str_replace( "'", ''', $incoming_comment['comment_content'] );
 
    return( $incoming_comment );
}
 
// This will occur before a comment is displayed
function plc_comment_display( $comment_to_display ) {
 
    // Put the single quotes back in
    $comment_to_display = str_replace( ''', "'", $comment_to_display );
 
    return $comment_to_display;
}
 
add_filter( 'preprocess_comment', 'plc_comment_post', '', 1);
add_filter( 'comment_text', 'plc_comment_display', '', 1);
add_filter( 'comment_text_rss', 'plc_comment_display', '', 1);
add_filter( 'comment_excerpt', 'plc_comment_display', '', 1);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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