Nofollow the date/time hyperlink in comment

Modifying core WordPress files, like class-walker-comment.php, is generally not recommended, as your changes will be overwritten with each WordPress update. Instead, you can achieve the same effect by using a child theme and custom functions. This way, your modifications remain intact across updates.

I tried a few different things but I was able to get it working using this technique: ( I am sure there are other solutions )

  1. Find your comments.php file in your theme (child theme preferably)
  2. Replace this: (or something similar, it is possible that themes can be slightly different depending.
wp_list_comments(
            [
                'style'       => 'ol',
                'short_ping'  => true,
                'avatar_size' => 42,
            ]
        );

With this:


        // Start output buffering
        ob_start();

        // Output comments
        wp_list_comments([
            'style'       => 'ol',
            'short_ping'  => true,
            'avatar_size' => 42,
        ]);

        // Capture the output
        $comments_list = ob_get_clean();
        // Regular expression to match date/time links and modify the hyperlink
        $pattern = '/<a .*?href="(.*?#comment-\d+)".*?>(.*?)<\/a>/i';
        $comments_list = preg_replace($pattern, '<a href="$1" rel="nofollow">$2</a>', $comments_list);
        // Output the modified list
        echo $comments_list;

tech