Answers.Body: <p>Use the <code>raw</code> filter on the replaced string (output), not <code>block.body</code> (input):</p>
  
  <pre><code>{% set str = block.body %}
  {{ str | replace('&lt;p&gt;', '&lt;p class="myClass" data-wow-duration="1s"&gt;') | raw }}
  </code></pre>
  
  <p>Also, some friendly advice: I'd like to point out that rewriting HTML in this way is <a href="http://blog.codinghorror.com/parsing-html-the-cthulhu-way/">pretty risky</a>.</p>
  
  <p><em>Shameless plug alert</em>, but I wrote a plugin called <a href="https://github.com/mmikkel/RetconHTML-Craft">Retcon HTML</a> which lets you manipulate your HTML content using PHP's <a href="http://php.net/manual/en/class.domdocument.php">DOMDocument</a> – a far safer approach :)</p>
  
  <p>This is how you could achieve your specific goal using Retcon's <a href="https://github.com/mmikkel/RetconHTML-Craft/wiki/Attr">Attr method</a>:</p>
  
  <pre><code>{{ block.body | retconAttr( 'p', { 'class' : 'myClass', 'data-wow-duration' : '1s' } ) }}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-21T01:28:55.503Z
Answers.Text: I was wondering if there was something like this. Thank you! Final solution: 
  `{{ block.body | retconAttr( 'p', { 'class' : 'myClass anotherClass', 'data-wow-duration' : '1' } ) }}`
Answers.UserDisplayName: Leah
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-21T06:49:10.367Z
Answers.Text: No worries, happy it could help you out!
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-21T01:16:49.510Z
Answers.LastActivityDate: 2015-04-21T01:30:29.403Z
Answers.LastEditDate: 2015-04-21T01:30:29.403Z
Answers.UserDisplayName: Mats Mikkel Rummelhoff
Body: <p>Currently I am using twig's replace filter to replace the tags:</p>
  
  <pre><code>{% set str = block.body | raw %}
  {{ str | replace('&lt;p&gt;', '&lt;p class="myClass" data-wow-duration="1s"&gt;') }}
  </code></pre>
  
  <p>But on output it's not outputting the actual tags but:</p>
  
  <pre><code>&amp;lt;p class=&amp;quot;myClass&amp;quot; data-wow-duration=&amp;quot;1s&amp;quot;&amp;gt;
  </code></pre>
  
  <p>How do I keep the tags as tags?</p>
  
Tags: <templating><string><replace>
Title: Replace <p> with <p class="myClass">
ThreadText: # Replace <p> with <p class="myClass">
  
  (Asked by: username_0 on 2015-04-21)
  
  Currently I am using twig's replace filter to replace the tags:
  
  ```
  {% set str = block.body | raw %}
  {{ str | replace('<p>', '<p class="myClass" data-wow-duration="1s">') }}
  
  ```
  
  But on output it's not outputting the actual tags but:
  
  ```
  &lt;p class=&quot;myClass&quot; data-wow-duration=&quot;1s&quot;&gt;
  
  ```
  
  How do I keep the tags as tags?
  
  **Tags:** templating, string, replace
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-04-21. Score: 7 | Accepted answer
  
  Use the `raw` filter on the replaced string (output), not `block.body` (input):
  
  ```
  {% set str = block.body %}
  {{ str | replace('<p>', '<p class="myClass" data-wow-duration="1s">') | raw }}
  
  ```
  
  Also, some friendly advice: I'd like to point out that rewriting HTML in this way is [pretty risky](http://blog.codinghorror.com/parsing-html-the-cthulhu-way/).
  
  *Shameless plug alert*, but I wrote a plugin called [Retcon HTML](https://github.com/mmikkel/RetconHTML-Craft) which lets you manipulate your HTML content using PHP's [DOMDocument](http://php.net/manual/en/class.domdocument.php) – a far safer approach :)
  
  This is how you could achieve your specific goal using Retcon's [Attr method](https://github.com/mmikkel/RetconHTML-Craft/wiki/Attr):
  
  ```
  {{ block.body | retconAttr( 'p', { 'class' : 'myClass', 'data-wow-duration' : '1s' } ) }}
  
  ```
  
  > **Comments:**
  > **username_0**: I was wondering if there was something like this. Thank you! Final solution:  `{{ block.body | retconAttr( 'p', { 'class' : 'myClass anotherClass', 'data-wow-duration' : '1' } ) }}`  
  > **username_1**: No worries, happy it could help you out!  
  
  ---
  
  