<p>Not a "real" answer because it won't fix your actual content, but I wrote <a href="https://github.com/mmikkel/RetconHTML-Craft" rel="nofollow">a plugin</a> that would make it easy to remedy your issue on the front end (i.e. in the template) –</p>

<p>To remove all <code>&lt;h1&gt;</code> and <code>&lt;h2&gt;</code> tags (content inside tags will not be removed):</p>

<pre><code>{{ entry.someRedactorField|retconChange(['h1','h2'], false) }}
</code></pre>

<p>To change <code>&lt;h1&gt;</code> and <code>&lt;h2&gt;</code> tags into <code>&lt;p&gt;</code> tags:</p>

<pre><code>{{ entry.someRedactorField|retconChange(['h1','h2'], 'p') }}
</code></pre>

<p>You can read more about the <code>rectonChange</code> filter used in the two examples above <a href="https://github.com/mmikkel/RetconHTML-Craft/wiki/Change" rel="nofollow">here</a>.</p>

CC BY-SA 3.0
2016-08-19T22:53:58.943Z
2016-08-19T22:53:58.943Z
Mats Mikkel Rummelhoff
<p>I set up a Redactor config to add h3 headings only. If I copy-paste texts from a text edition software like Microsoft Word and uses h1 or h2 for example in his document, these un-wanted headings will be pasted in the rich text field. In another way, if I add an heading tag like <code>&lt;h1&gt;</code> in the source code mode of Redactor, this unwanted heading will also be added.</p>

<p><strong>How can I prevent this and set a list of unwanted tags that could be dynamically deleted or converted in <code>&lt;p&gt;</code> ?</strong></p>

<p>There are <em>pasteBlockTags</em> and <em>pasteInlineTags</em> options in the Redactor doc (<a href="https://imperavi.com/redactor/docs/settings/paste/#setting-pasteBlockTags" rel="nofollow">https://imperavi.com/redactor/docs/settings/paste/#setting-pasteBlockTags</a>), but it doesn't seems possible to add these options inside the JSON file stored in <code>craft/config/redactor</code>.</p>

<p>I also tried to add a new <em>formattingAdd</em> option, which I called Remove format, and replace unwanted tags by <code>&lt;p&gt;</code>, but this is an annoying solution because it needs to review each pieces of texts.</p>

<control-panel><redactor><richtext>
How can I dynamically remove some unwanted formatting tags inside rich text fields?
# How can I dynamically remove some unwanted formatting tags inside rich text fields?

(Asked by: username_0 on 2016-08-19)

I set up a Redactor config to add h3 headings only. If I copy-paste texts from a text edition software like Microsoft Word and uses h1 or h2 for example in his document, these un-wanted headings will be pasted in the rich text field. In another way, if I add an heading tag like `#` in the source code mode of Redactor, this unwanted heading will also be added.

**How can I prevent this and set a list of unwanted tags that could be dynamically deleted or converted in  ?**

There are *pasteBlockTags* and *pasteInlineTags* options in the Redactor doc (<https://imperavi.com/redactor/docs/settings/paste/#setting-pasteBlockTags>), but it doesn't seems possible to add these options inside the JSON file stored in `craft/config/redactor`.

I also tried to add a new *formattingAdd* option, which I called Remove format, and replace unwanted tags by , but this is an annoying solution because it needs to review each pieces of texts.

**Tags:** control-panel, redactor, richtext

---

## 1 answers

### Answer by username_1 on 2016-08-19. Score: 4 | Accepted answer

Not a "real" answer because it won't fix your actual content, but I wrote a plugin that would make it easy to remedy your issue on the front end (i.e. in the template) –
To remove all  and  tags (content inside tags will not be removed):
{{ entry.someRedactorField|retconChange(['h1','h2'], false) }}

To change  and  tags into  tags:
{{ entry.someRedactorField|retconChange(['h1','h2'], 'p') }}

You can read more about the rectonChange filter used in the two examples above here.


---

