0

I want to hide/remove the "Your Name" field from the comments on a Drupal 7 site.

I am using the bamboo theme and Drupal 7.

I have seen a few threads for the but most are about removing the subject line, or are about Drupal 6 etc. I have tried a few different methods I have seen, but have not succeeded in getting this to work on Drupal 7 as of yet. Any advice?

3 Answers 3

1

The name input is not a required field, so the easiest thing would be to hide it using CSS.

Try the following:

.comment-wrapper .form-item-name { display: none; }

You could also use hook_form_alter(). Check for the $form_id for the comment form, then set: $form['FIELD NAME GOES HERE']['#access'] = FALSE;

7
  • Thanks for getting back to me so quickly. Any particular place to place the CSS option, or just in the main css file for the theme?
    – gdhp
    Commented Mar 3, 2014 at 14:01
  • generally speaking, place it at the bottom of your theme's stylesheet.
    – jdu
    Commented Mar 3, 2014 at 14:04
  • Unfortunately the first option doesn't seem to be working. Will try the second once I can work out the name of the field. For clarifiction what I'm trying to do here though, I want to remove the field from both the form and from display. I've used other techniques to get the field to disapear from the form, but then the username still shows up when the comment is submitted.
    – gdhp
    Commented Mar 3, 2014 at 14:10
  • I would highly recommend learning to use the HTML/CSS inspector in your favourite web browser. Hiding it with CSS should work, you just have to make sure the selectors are correct.
    – jdu
    Commented Mar 3, 2014 at 14:12
  • Thanks. Looks like this is just an area I will have to learn the skills at. I was hoping there'd a be a solution involving modules and/or settings, as opposed to actually needing to get code proficient. Seems like an odd thing not to have a module/option for.
    – gdhp
    Commented Mar 3, 2014 at 14:35
1

Found a solution to this that worked for me.

If you're theme has a comment.tpl.php file, if you search this file somehwere there will be a <?php print $author; ?> piece of script. Removing this worked for me. It's a bit of a hack, but stops the username still appearing in the developer tools, which means you can have authenticated users post anonymously.

1
  • It isn't a hack if you copy the file into your themes folder - this is a perfectly good way to override a template :-) Commented Apr 24, 2016 at 9:31
1

Had the same problem and solved it based on jdu's method. Insert following code into your themes template.php file inside your hook_form_alter() function:

if ($form_id == "comment_node_article_form") {
  $form['author']['#access'] = FALSE;
}

This needs to be done for all node types with comments enabled.

IMO this method is better than using css, since css only hides it from display, not from the rendered html.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.