Preventing iFrame from loading

I have an iframe code loading on my website, which plays a radio station automatically. Is there a way I can prevent the iFrame from loading on a certain page? I tried using the "display:none;" css, but that only hid the player and the radio still played in the background.

Thanks for your help

  • Kasia Swiderska
    • Support nomad

    Hello Kenmon,

    CSS only stops element from displaying, but whats there will still load. I would try with small code snippet in jQuery that would detach iframe element, something like that:

    <?php
    
    add_action( 'wp_footer', 'wpmudev_add_infoabouttime' );
    
    function wpmudev_add_infoabouttime() {
    	if (is_page(1)) {
    
    	?>
    <script>
    var removeiframe = jQuery('.iframeClass').detach();
    </script>
    	<?php
    }
    }

    That code adds a script to page footer - is_page(1) is for targeting specific page by its ID (1) and .iframeClass is selector for iframe you want to remove.
    It can be added to functions.php of child theme or used as MU plugin http://premium.wpmudev.org/manuals/wpmu-manual-2/using-mu-plugins/

    kind regards,
    Kasia

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.