I've got a problem with CKEditor in Drupal 8. I've searched related questions like CKeditor adds extra <p> tags, but almost all questions are related to Drupal 7.

So, my CKEditor automatically applies a <p>&nbsp</p> when I hit enter and don't type anything.


How can I disable this? I don't want to remove the padding or anything of a <p> tag. I need something that checks if the paragraph is empty and then don't display it.

  • This is standard ckeditor behavior. Use shift+enter to inserr breaks instead of paragraphs. – user21641 Oct 11 '17 at 15:02
  • I know that, but I don't want to do that. I want shift-enter to be the default behaviour. Because when a user accidentally presses enter after writing their article, there must not be another <p> tag ... – Rubenxfd Oct 11 '17 at 15:03

have you tried toggling off the "Convert line breaks into HTML (i.e. <br> and <p>)" setting on the text input format?

enter image description here

  • Yesss I did never enabled them =/ – Rubenxfd Oct 13 '17 at 7:34

A solution for Drupal 7: WYSIWYG module, br instead of p tags in Drupal 7. Although I am pretty sure you can use modify this for D8 as well.

function hook_wysiwyg_editor_settings_alter(&$settings, $context) // replace hook with your module name
  if($context['profile']->editor == 'ckeditor')
    $settings['enterMode'] = 2;
    $settings['shiftEnterMode'] = 1;
  elseif($context['profile']->editor == 'tinymce')
    $settings['forced_root_block'] = FALSE;
    $settings['force_br_newlines'] = TRUE;
    $settings['force_p_newlines'] = FALSE;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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