How to Add Whimsical Form Field Placeholders to WordPress Comment Forms

The Word­Press com­ment form is a hum­ble lit­tle thing: a few form fields, an expla­na­tion or two, and not much else, bar­ring any plu­g­ins or cus­tomiza­tions, that is.

Users who have left com­ments already will be greet­ed with a form that is already filled out the next time they vis­it, thanks to a cook­ie which Word­Press sets, but what about before their first comment?

Would-be com­menters are greet­ed by emp­ty form fields for their name, email address, and web­site address, which is straight­for­ward enough, but what if you want to jazz things up ever so slight­ly by adding some place­hold­er text to these form fields? 

We can accom­plish this eas­i­ly enough using the placeholder form fields attribute, and because I want­ed to add a bit of whim­sy to my forms, I’ve set it up so that a dif­fer­ent fake iden­ti­ty is used as a place­hold­er every time it is loaded.

To accom­plish this, add the fol­low­ing block of code to either your site’s func­tion­al­i­ty plu­g­in or to the appro­pri­ate func­tions file in your theme.

/**
 * Comments form customizations
 */
function custom_comment_form_args( $arg ) {
	$fake_name = custom_get_fake_name();
	$fake_email = strtolower( str_replace( array( '.', '\'', ' ' ), array( '', '', '.' ), $fake_name ) );
 $fake_url = strtolower( str_replace( array( ' ', '.', '\'' ), '', $fake_name ) );

	# Adjust form fields
	$arg['fields']['author'] = str_replace( 'text"', 'text" placeholder="' . $fake_name . '"', $arg['fields']['author'] );
	$arg['fields']['email'] = str_replace( 'email"', 'email" placeholder="' . $fake_email . '@example.com"', $arg['fields']['email'] );
	$arg['fields']['url'] = str_replace( 'url"', 'url" placeholder="http://' . $fake_url . '.example/"', $arg['fields']['url'] );

	return $arg;
}
add_filter( 'comment_form_defaults', 'custom_comment_form_args' );

/**
 * Get a fake name
 */
function custom_get_fake_name() {
	$names = array(
		'Mario Speedwagon',
		'Petey Cruiser',
		'Anna Sthesia',
		'Paul Molive',
		'Anna Mull',
		'Gail Forcewind',
		'Paige Turner',
		'Bob Frapples',
		'Walter Melon',
		'Nick R. Bocker',
		'Barb Ackue',
		'Buck Kinnear',
		'Greta Life',
		'Ira Membrit',
		'Shonda Leer',
		'Brock Lee',
		'Maya Didas',
		'Rick O\'Shea',
		'Pete Sariya',
		'Monty Carlo',
		'Sal Monella',
		'Sue Vaneer',
		'Cliff Hanger',
		'Barb Dwyer',
		'Terry Aki',
		'Cory Ander',
		'Robin Banks',
		'Jimmy Changa',
		'Barry Wine',
		'Wilma Mumduya',
		'Buster Hyman',
		'Poppa Cherry',
		'Zack Lee',
		'Don Stairs',
		'Saul T. Balls',
		'Peter Pants',
		'Hal Appeno',
		'Otto Matic',
		'Moe Fugga',
		'Graham Cracker',
		'Tom Foolery',
		'Al Dente',
		'Bud Wiser',
		'Polly Tech',
		'Holly Graham',
		'Frank N. Stein',
		'Cam L. Toe',
		'Pat Agonia',
		'Tara Zona',
		'Barry Cade',
		'Phil Anthropist', 
		'Marvin Gardens',
		'Phil Harmonic',
		'Arty Ficial',
		'Will Power',
		'Donatella Nobatti',
		'Juan Annatoo',
		'Stew Gots',
		'Anna Rexia',
		'Bill Emia',
		'Curt N. Call',
		'Max Emum',
		'Minnie Mum',
		'Bill Yerds',
		'Hap E. Birthday',
		'Matt Innae',
		'Polly Science',
		'Tara Misu',
		'Ed U. Cation',
		'Gerry Atric',
		'Kerry Oaky',
		'Midge Itz',
		'Gabe Lackmen',
		'Mary Christmas',
		'Dan Druff',
		'Jim Nasium',
		'Angie O. Plasty',
		'Ella Vator',
		'Sal Vidge',
		'Bart Ender',
		'Artie Choke',
		'Hans Olo',
		'Marge Arin',
		'Hugh Briss',
		'Gene Poole',
		'Ty Tanic',
		'Manuel Labor',
		'Lynn Guini',
		'Claire Voyant',
		'Peg Leg',
		'Jack E. Sack',
		'Marty Graw',
		'Ash Wednesday',
		'Olive Yu',
		'Gene Jacket',
		'Tom Atoe',
		'Doug Out',
		'Sharon Needles',
		'Beau Tie',
		'Serj Protector',
		'Marcus Down',
		'Warren Peace',
		'Bud Jet',
		'Barney Cull',
		'Marion Gaze',
		'Eric Shun',
		'Mal Practice',
		'Ed Itorial',
		'Rick Shaw',
		'Paul Issy',
		'Ben Effit',
		'Kat E. Gory',
		'Justin Case',
		'Louie Z. Ana',
		'Aaron Ottix',
		'Ty Ballgame',
		'Anne Fibbiyon',
		'Barry Cuda',
		'John Withawind',
		'Joe Thyme',
		'Mary Goround',
		'Marge Arita',
		'Frank Senbeans',
		'Bill Dabear',
		'Ray Zindaroof',
		'Adam Zapple',
		'Lewis N. Clark',
		'Matt Schtick',
		'Sue Shee',
		'Chris P. Bacon',
		'Doug Lee Duckling',
		'Mason Protesters',
		'Sil Antro',
		'Cal Orie',
		'Sara Bellum',
		'Al Acart',
		'Marv Ellis',
		'Evan Shlee',
		'Terry Bull',
		'Mort Ission',
		'Mark Ette',
		'Ken Tucky',
		'Louis Ville',
		'Colin Oscopy',
		'Fred Attchini',
		'Al Fredo',
		'Penny Tration',
		'Reed Iculous',
		'Chip Zinsalsa',
		'Matt Uhrafact',
		'Jack Dup',
		'Mike Roscope',
		'Lou Sinclark',
		'Faye Daway',
		'Javy Cado',
		'Tom Ollie',
		'Sam Buca',
		'Phil Andererv',
		'Sam Owen',
		'Mary Achi',
		'Ray Cyst',
		'Curtis E. Flush',
		'Holland Oats',
		'Helen Highwater',
		'Eddy Kitt',
		'Al Toesacks',
		'Sir Kim Scision',
		'Elle Bowdrop',
		'Yu Tube',
		'Ellis Dee',
		'Anna Lytics',
		'Sara Bellum',
		'Penny Trate',
		'Phil Erup',
		'Jenna Side',
		'Mary Nara',
		'Mick Donalds',
		'Amber Alert',
		'Vic Tory',
		'Bobby Pin',
		'Dom Inate',
		'Hugh Miliation',
		'Christian Mingle',
		'Juan Soponatime',
		'Dante Sinferno',
		'Ed Zupp',
		'Sarah Yevo',
		'Jess Thetip',
		'Arthur Itis',
		'Faye Sbook',
		'Carrie R. Pigeon',
		'Rachel Slurs',
		'Ty Pryder',
		'Cole Slaw',
		'Pat Ernity',
		'Deb Utant',
		'Luke Warm',
		'Travis Tee',
		'Clara Fication',
		'Paul Itician',
		'Deb Utant',
		'Moe Thegrass',
		'Carol Sell',
		'Scott Schtape',
		'Cody Pendant',
		'Frank Furter',
		'Barry Dalive',
		'Mort Adella',
		'Ray Diation',
		'Mack Adamia',
		'Farrah Moan',
		'Theo Retical',
		'Eda Torial',
		'Mae O\'Nayse',
		'Bella Ruse',
		'Yuri Thra',
		'Tucker Doubt',
		'Cara Larm',
		'Abel Body',
		'Sal Ami',
		'Colin Derr',
		'Cathy Derr',
		'Colin O\'Scopy',
		'Mel Anoma',
		'Adam Up',
		'Lou Zing',
		'Mark Key',
		'Sven Gineer',
		'Mick Rib',
		'Benny Ficial',
		'Genie Inabottle',
		'Gene Therapy',
		'Reggie Stration',
		'Lou Ow',
		'Lance Dorporal',
		'Lou Tenant',
		'Nick Knack',
		'Patty Whack',
		'Reuben Sandwich',
		'Hugo Slavia',
		'Aaron Spacemuseum',
		'Petey Atricks',
		'Dan Delion',
		'Terry Torial',
		'Cal Q. Later',
		'Jen Trification',
		'Indy Nile',
		'Ray Volver',
		'Minnie Strone',
		'Gustav Wind',
		'Paul Samic',
		'Vinny Gret',
		'Joyce Tick',
		'Cliff Diver',
		'Earl E. Riser',
		'Cooke Edoh',
		'Jen Youfelct',
		'Reanne Carnation',
		'Paul Misunday',
		'Chris P. Cream',
		'Gio Metric',
		'Caire Innet',
		'Marsha Mello',
		'Manny Petty',
		'Val Adictorian',
		'Lucy Tania',
		'Jaques Amole',
	);
	$random_name = array_rand( $names );

	return $names[ $random_name ];
}

That’s all there is to it. Your com­ment form will now ran­dom­ly choose an iden­ti­ty with which to pro­vide an exam­ple for what is expect­ed to your commenters.

Note that this will only work if your Word­Press theme is using the comment_form Word­Press func­tion to out­put the com­ment­ing form, oth­er­wise you’ll like­ly have to cre­ate a cus­tom com­ment­ing form in a child theme to imple­ment the above changes.

Fake names sourced from The Offi­cial Fake Names List.

Leave a Comment

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

Use your Gravatar-enabled email address while commenting to automatically enhance your comment with some of Gravatar's open profile data.

Comments must be made in accordance with the comment policy. This site uses Akismet to reduce spam; learn how your comment data is processed.

You may use Markdown to format your comments; additionally, these HTML tags and attributes may be used: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Rick Beckman