<p>Check out the <a href="https://github.com/mmikkel/RetconHTML-Craft" rel="nofollow">Retcon</a> plugin! </p>

<blockquote>
  <p>Retcon is a small Craft CMS plugin offering a series of easy-to-use Twig filters for manipulating HTML content.</p>
</blockquote>

<p>Specifically, it sounds like you need the <a href="https://github.com/mmikkel/RetconHTML-Craft/wiki/Wrap" rel="nofollow">wrap</a> method:</p>

<pre><code>{{ entry.body|retconWrap('iframe', '.videoWrapper') }}
</code></pre>

CC BY-SA 4.0
2018-09-18T15:24:06.250Z
Is there any way to pass multiple classes here? For example '.embed-responsive .embed-responsive-16by9'
Vaughn D. Taylor
CC BY-SA 4.0
2018-09-18T20:14:58.973Z
@VaughnD.Taylor I'd recommend posting [a new question](https://craftcms.stackexchange.com/questions/ask). This answer is almost 2 years old. Feel free to link back to this thread for reference.
Lindsey D
CC BY-SA 4.0
2018-09-18T21:24:26.053Z
I actually found a solution using Retcon. I feel like I should post it in case someone else has the same question.
Vaughn D. Taylor
CC BY-SA 4.0
2018-09-18T21:25:38.573Z
Sounds good! Asking & answering your own question is actually encouraged here on SE. :)
Lindsey D
CC BY-SA 4.0
2018-09-18T21:34:43.640Z
Sorry, I don't want to sound thick here ... should I post it as a comment, put it as a new answer here, or just ask a whole new question then answer it? I think it's the third option?
Vaughn D. Taylor
CC BY-SA 4.0
2018-09-18T21:36:49.940Z
Yup, the third option. Post a new question (reference this Q&A if you'd like), then you can immediately post your own answer to it. You can even do both simultaneously, by clicking the "Answer your own question" checkbox.
Lindsey D
CC BY-SA 3.0
2016-09-30T05:51:31.187Z
2016-09-30T07:00:25.523Z
2016-09-30T07:00:25.523Z
Lindsey D
<p>This article describes Twig macro that makes embedded youtube players responsive and lazy-loaded:</p>

<p><a href="http://craftsnippets.com/articles/responsive-and-lazy-loaded-youtube-videos-with-craft-cms?s=s" rel="nofollow noreferrer">Responsive and lazy-loaded youtube videos with Craft CMS</a></p>

CC BY-SA 4.0
2019-08-31T21:22:56.587Z
2019-08-31T21:22:56.587Z
Piotr Pogorzelski
<p>So I have been using <a href="https://css-tricks.com/NetMag/FluidWidthVideo/Article-FluidWidthVideo.php" rel="nofollow">this</a> CSS Tricks responsive video trick for years. The problem I'm having is that this new Craft site I built imported data over from EE into a single Redactor field.</p>

<p>Is there any way to run s conditional check that <code>if</code> there is a YouTube video embedded that would wrap a <code>div</code> around said content?</p>

<p>I'm probably asking too much but Craft has been amazing for the past few years I've using it. I fear the only way to do this would be to run an elaborate <code>MYSQL</code> commands to wrap that content in a <code>div</code> (or use JS to wrap each iframe) but I would love to be proven wrong!</p>

<redactor><conditional>
If YouTube in Redactor Then Wrap in Div
# If YouTube in Redactor Then Wrap in Div

(Asked by: username_0 on 2016-09-30)

So I have been using [this](https://css-tricks.com/NetMag/FluidWidthVideo/Article-FluidWidthVideo.php) CSS Tricks responsive video trick for years. The problem I'm having is that this new Craft site I built imported data over from EE into a single Redactor field.

Is there any way to run s conditional check that `if` there is a YouTube video embedded that would wrap a `div` around said content?

I'm probably asking too much but Craft has been amazing for the past few years I've using it. I fear the only way to do this would be to run an elaborate `MYSQL` commands to wrap that content in a `div` (or use JS to wrap each iframe) but I would love to be proven wrong!

**Tags:** redactor, conditional


---

## 2 answers

### Answer by username_1 on 2016-09-30. Score: 5 | Accepted answer

Check out the Retcon plugin! 

Retcon is a small Craft CMS plugin offering a series of easy-to-use Twig filters for manipulating HTML content.

Specifically, it sounds like you need the wrap method:
{{ entry.body|retconWrap('iframe', '.videoWrapper') }}

> **Comments:**
> **username_2**: Is there any way to pass multiple classes here? For example '.embed-responsive .embed-responsive-16by9'  
> **username_1**: @VaughnD.Taylor I'd recommend posting [a new question](https://craftcms.stackexchange.com/questions/ask). This answer is almost 2 years old. Feel free to link back to this thread for reference.  
> **username_2**: I actually found a solution using Retcon. I feel like I should post it in case someone else has the same question.  
> **username_1**: Sounds good! Asking & answering your own question is actually encouraged here on SE. :)  
> **username_2**: Sorry, I don't want to sound thick here ... should I post it as a comment, put it as a new answer here, or just ask a whole new question then answer it? I think it's the third option?  
> **username_1**: Yup, the third option. Post a new question (reference this Q&A if you'd like), then you can immediately post your own answer to it. You can even do both simultaneously, by clicking the "Answer your own question" checkbox.  

---

### Answer by username_3 on 2019-08-31. Score: 1

This article describes Twig macro that makes embedded youtube players responsive and lazy-loaded:

[Responsive and lazy-loaded youtube videos with Craft CMS](http://craftsnippets.com/articles/responsive-and-lazy-loaded-youtube-videos-with-craft-cms?s=s)


---

