{"id":2558,"date":"2012-09-29T23:28:44","date_gmt":"2012-09-29T23:28:44","guid":{"rendered":"http:\/\/www.dognmonkey.com\/techs\/?p=2558"},"modified":"2017-03-16T11:21:16","modified_gmt":"2017-03-16T18:21:16","slug":"fix-youtube-iframe-on-top-of-overlay-modals","status":"publish","type":"post","link":"https:\/\/www.dognmonkey.com\/techs\/fix-youtube-iframe-on-top-of-overlay-modals.html","title":{"rendered":"Fix Youtube Iframe On Top Of Overlay Modals"},"content":{"rendered":"<p style=\"text-align: center;\">2013-08-27 <i>The new editor from WordPress automatically moves the height and width right after the link which causes the script NOT to work. I have to modify so that it will work as long as the height is set at 315 px as default with youtube HD. Now it will work with the new editor. If we use the height without the value which will work great for all sizes of youtube, but it will change the amazon iframe with height also &#8211; most of amazon ads heights are 240px.<\/i><\/p>\n<blockquote><p>function add_video_wmode_transparent($html) {<br \/>\nif (strpos($html, &#8220;&lt;iframe&#8221; ) !== false) {<br \/>\n$search = array(&#8216;&#8221; height=&#8221;315&#8243;&#8216;, &#8216;?hd=1?hd=1&#8217;);<br \/>\n$replace = array(&#8216;?hd=1&amp;wmode=transparent&#8221; wmode=&#8221;Opaque&#8221; height=&#8221;315&#8243;&#8216;, &#8216;?hd=1&#8217;);<br \/>\n$html = str_replace($search, $replace, $html);<\/p>\n<p>return $html;<br \/>\n} else {<br \/>\nreturn $html;<br \/>\n}<br \/>\n}<\/p><\/blockquote>\n<p style=\"text-align: center;\">2013-08-14 Retested with ie8 and Safari &#8211; didn&#8217;t work &#8211; need to add &#8220;wmode=transparent&#8221; &#8211; New codes are below and make sure all iframe youtube has &#8220;frameborder&#8221; right after the &#8220;src&#8221; and not any other code in between like &#8220;allowfullscreen&#8221;.<\/p>\n<blockquote><p>function add_video_wmode_transparent($html) {<br \/>\nif (strpos($html, &#8220;&lt;iframe&#8221; ) !== false) {<br \/>\n$search = array(&#8216;&#8221; frameborder=&#8221;0&#8243;&#8216;, &#8216;?hd=1?hd=1&#8217;);<br \/>\n$replace = array(&#8216;?hd=1&amp;wmode=transparent&#8221; frameborder=&#8221;0&#8243; wmode=&#8221;Opaque&#8221;&#8216;, &#8216;?hd=1&#8217;);<br \/>\n$html = str_replace($search, $replace, $html);<\/p>\n<p>return $html;<br \/>\n} else {<br \/>\nreturn $html;<br \/>\n}<br \/>\n}<\/p><\/blockquote>\n<p style=\"text-align: center;\"><em>2012-10-04 After adding the Share This button to the post, I found out the codes below replace all iframes which Amazon banners and Share This also became &#8220;transparent&#8221;. I found another way for WordPress users to specifically replace only youtube iframes embedded codes. Place the codes below in the theme&#8217;s function.php<\/em><\/p>\n<blockquote>\n<p style=\"text-align: left;\"><em><\/em>function add_video_wmode_transparent($html) {<br \/>\nif (strpos($html, &#8220;&lt;iframe&#8221; ) !== false) {<br \/>\n$search = array(&#8216;&#8221; frameborder=&#8221;0&#8243;&#8216;, &#8216;?hd=1?hd=1&#8217;);<br \/>\n$replace = array(&#8216;?hd=1&amp;wmode=opaque&#8221; frameborder=&#8221;0&#8243;&#8216;, &#8216;?hd=1&#8217;);<br \/>\n$html = str_replace($search, $replace, $html);<\/p>\n<p>return $html;<br \/>\n} else {<br \/>\nreturn $html;<br \/>\n}<br \/>\n}<br \/>\nadd_filter(&#8216;the_excerpt&#8217;, &#8216;add_video_wmode_transparent&#8217;, 10);<br \/>\nadd_filter(&#8216;the_content&#8217;, &#8216;add_video_wmode_transparent&#8217;, 10);<\/p><\/blockquote>\n<p style=\"text-align: center;\"><em>This code works very well and Share This button doesn&#8217;t complain any more.<a class=\"ib2 fancybox.iframe\" title=\"fix youtube iframe z-index\" href=\"\/\/wordpress.org\/support\/topic\/dynamically-change-youtube-iframe-embeds-to-auto-add-transparent-mode\" target=\"_blank\"> The original codes.<\/a><\/em><\/p>\n<p style=\"text-align: center;\"><em>When we put Amazon iframe little displays with &#8216;frameborder=&#8221;0&#8243;&#8216; , it only show default Amazon&#8217;s\u00a0 ads.<\/em><\/p>\n<div class=\"igallery\">\n<p style=\"text-align: center;\"><em><\/em><a class=\"preview\" title=\"Generic Amazon iframe displays due to 'frameborder=&quot;0&quot;'\" href=\"\/media\/wpweb\/iframes\/amazon_iframe.jpg\" rel=\"lightbox[ifram]\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"Generic Amazon iframe displays due to 'frameborder=&quot;0&quot;'\" alt=\"\" src=\"\/media\/wpweb\/iframes\/tn_amazon_iframe.jpg\" width=\"250\" height=\"133\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><em>We need to remove the &#8216;frameborder=&#8221;0&#8243;&#8216; codes inside the ads.<\/em><\/p>\n<p style=\"text-align: center;\"><em><\/em><a class=\"preview\" title=\"Remove 'iframeborder=&quot;0&quot;' in Amazon codes\" href=\"\/media\/wpweb\/iframes\/amazon_iframe1.jpg\" rel=\"lightbox[ifram]\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"Remove 'iframeborder=&quot;0&quot;' in Amazon codes\" alt=\"\" src=\"\/media\/wpweb\/iframes\/tn_amazon_iframe1.jpg\" width=\"250\" height=\"37\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><em>The display will be good again.<\/em><\/p>\n<p style=\"text-align: center;\"><a class=\"preview\" title=\"good amazon iframes displays\" href=\"\/media\/wpweb\/iframes\/amazon_iframe3.jpg\" rel=\"lightbox[ifram]\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"good amazon iframes displays\" alt=\"\" src=\"\/media\/wpweb\/iframes\/tn_amazon_iframe3.jpg\" width=\"250\" height=\"131\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><em>When we use image pop-up modals like Fancybox, Shadowbox, Mediabox Advanced together with embedded iframe youtube video, the overlay will stay under the youtube frame on ie (internet explorer) browsers. The only way to fix this is to either add &#8220;? or &amp;wmode=&#8221;opaque&#8221; or &#8220;transparent&#8221;&#8221; at the end of every youtube link on your blog or fix it with <a title=\"stackoverflow\" href=\"\/\/stackoverflow.com\/questions\/8818036\/how-to-dynamically-add-wmode-transparent-to-youtube-embed-code\" target=\"_blank\">javascript<\/a>.<\/em><\/p>\n<p style=\"text-align: center;\"><em>To fix a single youtube iframe<\/em><\/p>\n<blockquote>\n<p style=\"text-align: left;\"><em><\/em>\/\/www.youtube.com\/embed\/zofscYJkS-8?rel=0&amp;wmode=&#8221;opaque&#8221;<\/p>\n<p style=\"text-align: left;\">\/\/www.youtube.com\/embed\/zofscYJkS-8&amp;wmode=&#8221;opaque&#8221;<\/p>\n<\/blockquote>\n<p style=\"text-align: center;\"><em>If we already have too many posts with embedded iframe youtube with &#8220;?rel=0&#8221; and no flag mixed then add this script in the footer.php or before the &lt;\/body&gt; of the html page.<\/em><\/p>\n<blockquote>\n<p style=\"text-align: left;\"><em><\/em>&lt;script type=&#8221;text\/javascript&#8221;&gt;<br \/>\nwindow.onload = function() {<br \/>\nvar frames = document.getElementsByTagName(&#8220;iframe&#8221;);<br \/>\nfor (var i = 0; i &lt; frames.length; i++) {<br \/>\nframes[i].src += &#8220;?rel=0&amp;wmode=opaque&#8221;;<br \/>\n}<br \/>\n}<br \/>\n&lt;\/script&gt;<\/p>\n<\/blockquote>\n<p style=\"text-align: center;\"><em>Youtube without &#8220;?rel=0&#8221;<\/em><\/p>\n<p style=\"text-align: center;\">&lt;p style=&#8221;text-align: center;&#8221;&gt;&lt;iframe src=&#8221;\/\/www.youtube.com\/embed\/zofscYJkS-8&#8243; frameborder=&#8221;0&#8243; width=&#8221;420&#8243; height=&#8221;236&#8243;&gt;&lt;\/iframe&gt;&lt;\/p&gt;<\/p>\n<p style=\"text-align: center;\"><iframe loading=\"lazy\" src=\"\/\/www.youtube.com\/embed\/zofscYJkS-8\" height=\"236\" width=\"420\" frameborder=\"0\"><\/iframe><\/p>\n<p style=\"text-align: center;\">Fancybox 2 modal pop-up (should be on top of these 2 youtube iframe overlay) using ie (internet explorer). Others browsers should work without the fix.<\/p>\n<p style=\"text-align: center;\"><a class=\"idogb\" title=\"fancybox 2.0 should work over the youtube iframe\" href=\"\/media\/wpweb\/sm_youtubeoverlay.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone\" title=\"fancybox 2.0 should work over the youtube iframe\" alt=\"\" src=\"\/media\/wpweb\/tn_youtubeoverlay.jpg\" width=\"250\" height=\"164\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><em>Youtube with &#8220;?rel=0&#8221;<\/em><\/p>\n<p style=\"text-align: center;\">&lt;p style=&#8221;text-align: center;&#8221;&gt;&lt;iframe src=&#8221;\/\/www.youtube.com\/embed\/zofscYJkS-8?rel=0&#8243; frameborder=&#8221;0&#8243; width=&#8221;420&#8243; height=&#8221;236&#8243;&gt;&lt;\/iframe&gt;&lt;\/p&gt;<\/p>\n<p style=\"text-align: center;\"><iframe loading=\"lazy\" src=\"\/\/www.youtube.com\/embed\/zofscYJkS-8?rel=0\" height=\"236\" width=\"420\" frameborder=\"0\"><\/iframe><\/p>\n<\/div>\n<p style=\"text-align: center;\"><ul class=\"lcp_catlist\" id=\"lcp_instance_0\"><\/ul><\/p>\n","protected":false},"excerpt":{"rendered":"<p>2013-08-27 The new editor from WordPress automatically moves the height and width right after the link which causes the script NOT to work. I have to modify so that it will work as long as the height is set at 315 px as default with youtube HD. Now it will work with the new editor. <a href=\"https:\/\/www.dognmonkey.com\/techs\/fix-youtube-iframe-on-top-of-overlay-modals.html\" class=\"more-link\">&#8230;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12,20],"tags":[232,231,230],"class_list":["post-2558","post","type-post","status-publish","format-standard","hentry","category-pop-ups","category-wordpress","tag-opaque","tag-transparent","tag-wmode"],"views":2543,"_links":{"self":[{"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/posts\/2558","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/comments?post=2558"}],"version-history":[{"count":3,"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/posts\/2558\/revisions"}],"predecessor-version":[{"id":6356,"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/posts\/2558\/revisions\/6356"}],"wp:attachment":[{"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/media?parent=2558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/categories?post=2558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dognmonkey.com\/techs\/wp-json\/wp\/v2\/tags?post=2558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}