Remove automatic P tag on static block

Remove automatic P tag on static block

September 1, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Remove automatic P tag on static block

Removing Automatic

Tags from Static Blocks in Magento

Are you struggling with unwanted automatic <p> tags appearing on your static blocks or pages in Magento, even though you’ve disabled the WYSIWYG editor? You’re not alone! Let’s dive into how to remove these pesky tags without touching the editor.

Understanding the Issue

The default Magento setup automatically wraps any text entered into a static block with a <p> tag. This is done by the core tiny_mce JavaScript library, which is used for the WYSIWYG (What You See Is What You Get) editor. Even if you’ve disabled the editor, the automatic wrapping of text with <p> tags remains.

The Misleading JS File

Many developers initially look into js/mage/adminhtml/wysiwyg/tiny_mce/setup.js to find a solution. However, this file only handles the initialization and configuration of the WYSIWYG editor—it doesn’t control the automatic <p> tag insertion.

The Core Culprit

The real culprit lies in lib/tiny_mce/plugins/wordcount/plugin.js. This file contains the code that automatically wraps text entered into a static block with a <p> tag. To remove these tags, we need to modify this core Magento file.

Important Note: Directly editing core files is generally discouraged as it can cause issues during updates. A better approach would be to create a custom module and override the necessary files. For a detailed guide on creating extensions in Magento 2, check out our official documentation.

Overriding the Core File

To permanently remove the automatic <p> tag wrapping:

  1. Create a new module directory under app/code/Vendor_Name/Module_Name.

    • Replace Vendor_Name with your vendor name (e.g., “LaravelCompany”).
    • Replace Module_Name with a unique identifier for your module, such as “RemovePtag”.
  2. Inside the app/code/Vendor_Name/Module_Name directory, create an etc/module.xml file:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Modularity/etc/module.xsd">
    <module name="Vendor_Name_Module_Name" setup_version="1.0.0">
        <sequence>
            <module name="Magento_TinyMce"/>
        </sequence>
    </module>
</config>
  • This file tells Magento to load your module after the Magento_TinyMce module.
  1. Create a new directory app/code/Vendor_Name/Module_Name/view/adminhtml/templates/tinymce/plugins/wordcount.

  2. Inside this new directory, create a copy of the original plugin.js file and rename it to something like plugin_no_p_tag.js.

  3. Open the original plugin.js file located at lib/tiny_mce/plugins/wordcount/plugin.js. Search for this line:

editor.onKeyUp.add(function (ed, e) {
    ed.execCommand('mceInsertContent', false, '<p>' + ed.selection.getContent() + '</p>');
});
  • Comment out or remove the entire function to disable the automatic <p> tag insertion.
  1. Save your changes and clear Magento’s cache using php bin/magento cache:clean in the command line.

Conclusion

Removing the automatic <p> tags from static blocks requires a bit of core file overriding, as it isn’t handled by the WYSIWYG editor configuration alone. By following this guide, you can create a custom module that overrides the core plugin.js file and eliminates those unwanted <p> tags.

Remember, directly editing core files should be avoided if possible. Always consider creating a custom module to maintain your changes during updates.

Happy coding!

Magento 2 Extensions Admin Configuration

Our network