0

The Problem:

I try delete the tag generates by a iframe after is loaded.

The iframe is for load a video but then it loads some tags like this <div role="contentinfo" class="dmp_VideoInfo dmp_is-hidden" aria-hidden="true"> the which I need delete

Explain the iframe process

I've inserted this frame in my post:

<iframe width="480" height="270" frameborder="0" src="//www.dailymotion.com/embed/video/x68s7j8?autoPlay=0&amp;logo=0&amp;related=0&amp;social=0" allowfullscreen="allowfullscreen"></iframe>

Then that the video is loaded, it create a divs with a text I want remove the div with all text.

<div role="contentinfo" class="dmp_VideoInfo"><h1 class="dmp_VideoInfo-title dmp_u-cf"><a class="dmp_VideoInfo-title-text dmp_VideoInfo-item" aria-label="Video title: MORE TEXT with TITLE xD" href="http://www.dailymotion.com/video/xxxxxx" target="_blank">VIDEO NAME TEXT #text</a></h1><h3 class="dmp_VideoInfo-duration"><span class="dmp_VideoInfo-duration-text dmp_VideoInfo-item dmp_cursor-default" aria-label="Video duration: 11 minutes, 25 seconds" href="#">TOTAL TIME</span></h3><h2 class="dmp_VideoInfo-owner"><a class="dmp_VideoInfo-owner-text dmp_VideoInfo-item" aria-label="Video owner: Ownername xDD" href="http://www.dailymotion.com/myuser" target="_blank">Ownername xDD</a></h2></div>

What I've tried?

I've used DOM and preg_replace function, with a code like this (in functions.php):

function antiponchada($content) {
    if (is_single()){
        $object = new DOMDocument();
        $object->LoadHTML($content);
        $xpathobj= new DOMXPath($object);
        $result=$xpathobj->query('div[@class="dmp_VideoInfo"]'); //example only
        foreach($result as $node){
            $node->parentNode->removeChild($node);
        }
        return $object->saveHTML();
    }
    else {
        return $content;
    }
}
add_filter("the_content", "antiponchada", 999); // also without 999

and also (the regex is nice, relax.):

function antiponchada($content) {
    if (is_single()){

        $newcontent = preg_replace('/<div role="contentinfo" class="dmp_VideoInfo dmp_is-hidden" aria-hidden="true">.+<\/div>/',"",$content);
        return $newcontent;
    }
    else {
        return $content;
    }
}

add_filter("the_content", "antiponchada", 999);

What I need?:

I need delete the tags generated after of load the video of the iframe

closed as off-topic by Michael, Jacob Peattie, kraftner, cjbj, Pat J Nov 16 '17 at 17:35

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

  • Is this "div" in the content ? look what is in this variable with var_dump($content); e.g. – mmm Nov 11 '17 at 18:20
  • @mmm I've edited the post for explain better. Please reload. I want delete a div because contain a text with a link (to the server where I upload the video) – Milor123 Nov 11 '17 at 18:28
  • 2
    you cant manipulate the html inside the iframe if its third party iframe.. – Shibi Nov 11 '17 at 20:02
1

You can't, it's as simple as that.

Why Not?

First of all, because the DIV is not part of your content. It's either generated by WordPress' filters, or the browser itself. So, you can't do preg_replace on something that doesn't exist.

Secondly, there's a matter of cross-domain policy. It's not possible to manipulate the content of an iframe unless the two webpages belong to the same domain. Anything else, and you will get a security error. This is intentional, and to prevent acts such as spoofing.

For further information, take a look at this link.

Not the answer you're looking for? Browse other questions tagged or ask your own question.