<p>Actually, the <code>striptags</code> filter (which is just a wrapper for the PHP <a href="http://php.net/manual/en/function.strip-tags.php" rel="noreferrer">strip_tags</a> function) removes all HTML tags <em>except the ones you pass in</em>.</p>

<p>In other words, if you want to remove <code>&lt;p&gt;</code> tags, just use the <code>striptags</code> filter without any parameters:</p>

<pre><code>{# Will remove all HTML tags #}
&lt;p class="slider--text"&gt;{{ product.intro|striptags|raw }}&lt;/p&gt;
</code></pre>

<p>If there are other tags you want to retain, you'll need to pass those in:</p>

<pre><code>{# Will remove all tags except &lt;br&gt; and &lt;img&gt; #}
&lt;p class="slider--text"&gt;{{ product.intro|striptags('&lt;br&gt;&lt;img&gt;')|raw }}&lt;/p&gt;
</code></pre>

<p>For a different take on stripping tags, you can use <a href="https://github.com/mmikkel/RetconHTML-Craft" rel="noreferrer">the Retcon plugin</a> (which I wrote). With Retcon, you can remove all <code>&lt;p&gt;</code> tags (and only <code>&lt;p&gt;</code> tags; retaining their contents as well as all other tags) easily by using the <a href="https://github.com/mmikkel/RetconHTML-Craft/wiki/Change" rel="noreferrer"><code>retconChange</code></a> filter:</p>

<pre><code>&lt;p class="slider--text"&gt;{{ product.intro|retconChange('&lt;p&gt;', false) }}&lt;/p&gt;
</code></pre>

CC BY-SA 3.0
2017-01-21T14:04:07.080Z
2017-01-21T15:28:28.473Z
2017-01-21T15:28:28.473Z
Mats Mikkel Rummelhoff
<p>I've seen how you can remove html tags with twig in other posts here so I am using:</p>

<pre><code>&lt;p class="slider--text"&gt;{{ product.intro|striptags('&lt;p&gt;')|raw }}&lt;/p&gt;
</code></pre>

<p>To remove the <code>&lt;p&gt;</code> tag that redactor adds automatically. However for some reason it is not removing it. Anyone have any ideas. Have I missed something glaringly obvious?</p>

<p>Cheers</p>

<templating>
striptags not removing <p> tag?
# striptags not removing <p> tag?

(Asked by: username_0 on 2017-01-21)

I've seen how you can remove html tags with twig in other posts here so I am using:
{{ product.intro|striptags('')|raw }}

To remove the  tag that redactor adds automatically. However for some reason it is not removing it. Anyone have any ideas. Have I missed something glaringly obvious?
Cheers

**Tags:** templating

---

## 1 answers

### Answer by username_1 on 2017-01-21. Score: 13

Actually, the striptags filter (which is just a wrapper for the PHP strip_tags function) removes all HTML tags except the ones you pass in.
In other words, if you want to remove  tags, just use the striptags filter without any parameters:
{# Will remove all HTML tags #}
{{ product.intro|striptags|raw }}

If there are other tags you want to retain, you'll need to pass those in:
{# Will remove all tags except  and  #}
{{ product.intro|striptags('')|raw }}

For a different take on stripping tags, you can use the Retcon plugin (which I wrote). With Retcon, you can remove all  tags (and only  tags; retaining their contents as well as all other tags) easily by using the retconChange filter:
{{ product.intro|retconChange('', false) }}


---

