如何确定我的内容是否有Instagram嵌入?

时间:2017-01-30 13:14:53

标签: php wordpress facebook youtube instagram

我网站中的帖子包含来自以下任何嵌入的视频(单个)。

  1. 的Youtube
  2. Instagram的
  3. 我的问题是在前端获取它们时我想知道我的内容是否有嵌入,如果是,嵌入了以下哪个。 ( iframe存在检​​查是一种(脏)方式,它仍然为Instagram工作

    PHPCODE:

        $video_start = strpos($singlePost->post_content, "<iframe");//Get to the start of the iframe(video)
        $video_stop = strpos($singlePost->post_content, "</iframe>");//Get to the end of the iframe(video)
        $iframe_content = substr($singlePost->post_content, $video_start, $video_stop);
        $xpath = new DOMXPath(@DOMDocument::loadHTML($iframe_content));
        $iframe_src = $xpath->evaluate("string(//iframe/@src)");
        $parsed_url = parse_url($iframe_src);
        $host = $parsed_url['host'];
    
        if(strpos($host, "youtube") !== false) { // If it is a youtube video append this
            $iframe_src = $iframe_src."?rel=0";// This option has to be appended of youtube URL's
            $related_social_icon = "youtube";
            $related_social_media = "youtube";
        }
    
    <iframe class="<?php echo $iframe_class; ?>" src="<?php echo $iframe_src; ?>" style="background-size: cover;" allowfullscreen></iframe>
    

    上面的代码适用于youtube,但是当插入instagram作为blockquote标签时不适用于Instagram coz,但如果你回应它们,它将立即成为iframe标签,因为其中有脚本。

1 个答案:

答案 0 :(得分:0)

我会选择这样的事情:

add_filter('the_content', function($content) {
    $identifier = '<embed';
    if (strpos($content, $identifier) !== false) {
        // identifier found
        $content = '<h1>This page includes an embed</h1>'.$content;
    }
    return $content;
});

我不确定你的嵌入是怎样的,你在谈论iframe。因此,您需要找到一些可以检查的标识符。

您的帖子可能已被低估了,因为它可能有更多信息?