Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

auto insert date and time (string) into comment_content WordPress


This is an add-on request to this previous (solved) question...
The previous question added another 20 digit number every time the comment was updated. I don't want that to happen... only when the comment is first posted.

I now want to insert a date and time string AND a random 20 digit number into the comment text... e.g.

16th March 2020 at 2030hrs (and the 20 digit number) will look like...
2020-03-16-2030 - 12345678909876512345

Answers (1)


Rempty answers:

try this code

function filter_preprocess_comment_rem( $commentdata ) {
$date=date("Y-m-d H:i");
$content=$content." ".$date." - ".$random;
return $commentdata;

add_filter( 'preprocess_comment', 'filter_preprocess_comment_rem', 10 );

function bwd_random_code2($digits = 20) {
$code = [];
for ($i = 0; $i < 20; $i++) {
$code[] = rand(0, 9);

return implode("", $code);

pjeaje comments: