I have a "Filtered HTML" text field and have the convert line breaks to <br> & <p> tags option turned on in the configuration but when I'm adding content to a "Filtered HTML" field and use Shift + Enter to create a newline within the same paragraph Drupal seems to be adding in two <br> tags rather than one, which I'd expect.

For an example the text

"I'm having
a great day"

gets turned into

"I'm having<br><br>
a great day"

Is there any way to alter this behaviour to add just one <br> tag instead of two?

1 Answer 1


The only way I've found of resolving this is to replace the two <br /> tags with one using a str_replace in the field preprocess function. I've placed an example below.

function theme_preprocess_field(&$vars) {
  switch($vars['element']['#field_name']) {
    // When pressing Shift + Enter in WYSIWYG editor to create a new line it outputs two <br /> tags, not one.
    case "field_description":
      $vars["items"][0]["#markup"] = str_replace("<br /><br />", "<br />", $vars["items"][0]["#markup"]);


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.