I run a couple of WordPress sites that contain IFRAMES.
The problem I had was that the content of the IFRAMES wasn’t updating when a visitor arrived at the site. They would see content that was hours or even days out of date.
In each of my sites I was generating files which updated every ten to fifteen minutes. This was done using a small programme that I wrote which generated small HTML files on the site itself. The IFRAME was then used to display that HTML file. However, caching in the site prevented that and insisted on dishing up a cached version which was out of date.
I took a two pronged approach.
The first objective was to tell the IFRAME to load a different filename each time the page was loaded. Obviously I couldn’t rename the origin file, so I added a parameter to the file request in the form “file.htm?t=X”. Now X had to be different each time the page was loaded so I had to enable PHP on the page and then create a timestamp date(“U”) so that X would change every second.
The resulting code appears as follows:
<?php
$cacheN=date('U');
echo("<iframe style='background-color: white;' src='/file.htm?cache=$cacheN' height='300'></iframe>");
?>
This will force the IFRAME to search for src=”/file.htm?cacheN=1534593560 or similar where the number changes every second. The parameter “cacheN” will be passed to the file but as it is meaningless it will be ignored and file.htm will be loaded.
Naturally to run PHP on a WordPress page will require a plugin or a facility within the theme being used.
The second method I used (a belt and braces approach) was to add a line to the head of the page (which can either mean another plugin or manually editing your theme’s header.php file)
<link rel="preload" href="/file.htm" type="text/html">
Examples in action (on the righthand sidebars) –
https://martinscriblerus.com
https://headrambles.com/