问题是:
加载后,我尝试删除iframe生成的标记。
iframe用于加载视频,但它会加载一些如下标记<div role="contentinfo" class="dmp_VideoInfo dmp_is-hidden" aria-hidden="true">
the which I need delete
解释iframe过程我在帖子中插入了这个框架:
<iframe width="480" height="270" frameborder="0" src="//www.dailymotion.com/embed/video/x68s7j8?autoPlay=0&logo=0&related=0&social=0" allowfullscreen="allowfullscreen"></iframe>
然后加载视频,它会创建一个
divs 带文本
我要删除包含所有文本的div。
<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>
我尝试了什么我用过
DOM 和
preg_replace 函数,代码如下(在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
还有(regex很好,放松):
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);
我需要什么我需要删除加载iframe视频后生成的标签