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:

    add_action( 'wp_footer', 'wpmudev_add_infoabouttime' );
    function wpmudev_add_infoabouttime() {
    	if (is_page(1)) {
    var removeiframe = jQuery('.iframeClass').detach();

    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

    kind regards,

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.