4

When we insert content into ckeditor field,suppose we write single line of text into ckeditor without any html tag, why its wrapping paragraph tag automatically around the text .

I need to remove this paragraph tag because its breaking my page's structure.

3
  • 1
    That's how ckeditor works, it always has at least one block level tag at the root of the document. Have a look through their docs and see if you can find an option to disable the behaviour, if you can it'll be fairly straightforward to apply that option via drupal. Last time I checked there was no good way to do it, you had to abuse a combination of other features to get it to work which may have undesirable side-effects
    – Clive
    Apr 5, 2017 at 9:11
  • I am also having the same issue
    – user52318
    Apr 5, 2017 at 9:38
  • 1
    Why are you using CKEditor if you don’t want any html on that field? Furthermore why does a P tag break your layout? The easy solution here is disable the format or recreate the field as a textarea only.
    – Kevin
    Dec 22, 2017 at 3:35

4 Answers 4

3

In Drupal 8, you may need to implement hook_editor_js_settings_alter and set config.autoParagraph to false, as referenced here: CKEDITOR.config.autoParagraph

/**
 * Implements hook_editor_js_settings_alter().
 */
function MODULE_editor_js_settings_alter(array &$settings) {
  foreach ($settings['editor']['formats'] as $name => $value) {
    $settings['editor']['formats'][$name]['editorSettings']['autoParagraph'] = FALSE;
  }
}
1
0

In Drupal 7 you have to go to admin/config/content/ckeditor press "edit" in the profile you want to change, and then under "Custom JavaScript configuration" (in advanced options section) add this line:

config.enterMode = CKEDITOR.ENTER_DIV;

more info in the original answer by alex-petrov:

https://drupal.stackexchange.com/a/30995/55010

0

In Drupal 8 using CKeditor if you change the text format to 'Full HTML' (to allow div tags) then click on source and then change the <p> for a <div> then it will not automatically add the <p> tags in next time it loads the content.

This is because, (as clive mentioned) there needs to be a block level element at the root of the document.

This is often less problematic than wrapping it in a p tag as sites are less likely to have global div styles, spacing, borders, padding, etc.

0

If you don't have a <p> in the Allowed HTML tags and enable the "Limit allowed HTML tags and correct faulty HTML" filter no <p> will be output on the front end. These settings appear per text format seen at /admin/config/content/formats.

The Allowed Formats module allows you to restrict certain fields to specific formats. This way you can restrict this field to a specific text format, a format that does not allow <p> tags, but allow them everywhere else.

Your Answer

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