I am trying to remove Your email address will not be published. line from comment form in twentythirteen and twentyfourteen default themes.
I have tried this:
function alter_comment_form_fields($fields){
unset($fields['comment_notes_before']);
return $fields;
}
add_filter('comment_form_default_fields','alter_comment_form_fields');
and this:
function alter_comment_form_fields($fields){
$fields['comment_notes_before'] = '<p>Email address not required.</p>';
return $fields;
}
add_filter('comment_form_default_fields','alter_comment_form_fields');
Nothing seems to work. I have also found this ticket
https://core.trac.wordpress.org/ticket/14510 Would appreciate if someone can point me to some direction.
Yor code is totally wrong here. Your idea here is not bad. If you have a look at the default comment_form, you will see
$fields
consist of the following, author, email and URL.That is why your code doesn’t work, as
comment_notes_before
aren’t in the$field
field.I personally think here that the proper way to go here is to copy the first section of the
comment_form()
to your theme, rename it and do all your changes in there, and just hooking it back to the proper filter.My reasoning here is, firstly proper localization of the
comment_form()
within your theme. And secondly, I’m using a jquery based validation system, and for this to work properly, the way to go here is copying the first part of thecomment_form()
. This is tried and tested, you can see my question that I raised here on this particular subject.So after all this said, here is what I’m currently using in my theme. You will need to do exactly the same. You just have to change want to need to what you want.
Solution if submit button disappears and notes:
In case you lose the submit button of your form, in addition to Pieter Goosen’s answer, you should add those lines to the
defaults
array parameters list:So I’ll rewrite his full code with this:
Important notes:
1- Remember that the keyword “pietergoosen” is the “Text Domain” or the theme name that you find in “style.css” of your theme. It worked for me to put anything random firstly, but then it’s better to use it the right way.
2- You don’t have to modify the main theme’s
functions.php
to make this work. This will cause your work to vanish after updates. It’s good practice to create a new child theme. All you have to do after creating the child theme is create a new file calledfunctions.php
, and start it with<?php
, and then write the code of the form. DO NOT ENDfunctions.php
WITH THE COMMON PHP CODE ENDING?>
. This is simply the wordpress syntax forfunctions.php
.Cheers!