Site logo

Archived topic

Hide YouTube video iframe for mobile view

3 replies · Started by Lorand on January 11, 2022

Viewing posts 1–4 of 4

Hello :)

Example of article on my website : https://www.android-logiciels.fr/mon-compte-retraite/

I would like to hide YouTube video iframe for mobile view.
I tried to add this hook (container content), but it doesn't work because I am not an expert in coding :(

function custom_script(){
<script>
jQuery(document).ready(function($){
    jQuery('iframe[src*="youtube"]').each(function() {
		jQuery(this).addClass('youtube_iframe');
    }); 
});
</script>
<style>
@media screen and (max-width: 500px) {.youtube_iframe { display:none; }}
</style>

Many thanks in advance if someone can help me ;)

Hi there,

how is the YouTube video being added to the site ?

If its just in the editor - switch to code view and wrap your iframe code in a div with the hide-on-mobile class eg.

<div class="hide-on-mobile">
Add your iframe code here
</div>

Hello David :)

Thank you for your reply.
Here is what I added in the functions.php of my child theme and it works.

@media screen and (max-width: 500px) { iframe {
display:none !important;
}}

If it can help other users ;)

Glad to hear you found your solution!

This archived topic is closed to new replies.