• Hello, I do not feel that I need the email field, but I would be interested in knowing the location of any readers I might someday have. So I would like use the email field as a “City, State, Country” field.

    I’ve made changes to my theme’s comments.php file and have managed to change the label of the “Email” field to say”City, State, Country.” That was easy.

    But I would like for this info to display under the vistor’s name once they have posted their comment. I cannot figure out how to do this. Any ideas?

    I did find a plugin that will insert a new comment field, but I would prefer to not rely on a plugin if I don’t really need to.

    Thanks.

Viewing 9 replies - 1 through 9 (of 9 total)
  • You can use the WordPress function get_comment_author_email to retrieve the information stored in the wp_comments table:

    https://codex.www.ads-software.com/Template_Tags/get_comment_author_email

    Use that function in your theme’s comments.php file and display the information wherever you think it’s appropriate.

    Note that the comment_author_email field will hold 100 characters and if you try to store longer values in there, it will either error out of the value will be truncated.

    Thread Starter jimclay75051

    (@jimclay75051)

    Thank you, that did help with displaying the field. The new problem is that the email field seems to only recognize information that is in an email format. It does not retain text in a City, State, Country format. So that kills that idea.

    If your theme utilizes the html5 comment form, then the input markup is like <input name="email" type="email" ... />
    This instructs the browser to only accept a valid email address.

    There is a filter comment_form_field_{$name} firing for each comment form field, so we can manipulate that markup before outputting it. Adding this into your functions.php will change type=”email” to type=”text” :

    add_filter('comment_form_field_email', 'my_edit_comment_form_fields');
    function my_edit_comment_form_fields( $field ) {
    	return str_replace('type="email"', 'type="text"', $field);
    }

    Thread Starter jimclay75051

    (@jimclay75051)

    Thanks Anastis, I’ll give that a try.

    Thread Starter jimclay75051

    (@jimclay75051)

    Hey Anastis, I’ve given this a try and it did not change anything anything. I appreciate your effort. One question, is there another php file besides functions.php that I might try? My functions file does not have much in it.

    Moderator bcworkz

    (@bcworkz)

    It could be your theme does not use the default comment_form() method of showing the form, in which case Anastis’ code may not work. functions.php of the current theme is the correct place for the code regardless of other content, placing it at the end free of other content should be fine. You could create a small, simple plugin as an alternate code vehicle, but you shouldn’t need to.

    If your theme has a custom form, it may or may not have a filter you can use. If not, you could create a child theme, and customize the form template or code, overriding the theme’s default. Exactly how that would be done depends on the theme. If you are using an open source theme, what is it? Someone may know of a workaround, or help you find one.

    Thread Starter jimclay75051

    (@jimclay75051)

    Hi bcworkz, I’m using a paid for theme called Striking, which is very nice.

    I think I’m going to spend some time on this and use this as way to learn more about php and css. I’m going to keep Anastis code and eventually I’ll figure out where and how to use it.

    I what to be able to understand how to change the look of the comment form. I’m thinking it should be possible to use the comment form as microblog, but I want to give it a different look.

    Moderator bcworkz

    (@bcworkz)

    Well, with paid themes I’m only guessing since I cannot access the theme’s source code, and it’s unethical to publish such code.

    Typically, theme’s comments are handled by the comments.php file of the theme. That page is usually divided into three sections: when there’s comments, when there are no comments, and the comment form. The comment form is either directly output by the page, or a function is called to display the form. That function could be on the same page, or it may be on functions.php, or somewhere else.

    Once you learn a little PHP, you should be able to identify the portion that outputs the form. Then it’s a matter of altering it to suit your needs. To protect your customizations when the theme is updated, create a child theme to contain your changes. Copy the comments.php page to your child and it will be used instead of the parent’s. You are free to alter the child copy at will.

    That’s about all I can tell you without knowing the source code. Good luck with your learning adventure!

    +1 for everything bcworkz said.

    Since it’s a paid theme, you should contact your theme’s developer(s) and they should be able to guide you around their code.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Repurpose Comment Email Field’ is closed to new replies.