douguai6716 2017-01-30 13:14
浏览 70

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

The posts in my site has video(single) from anyone of the following embeds.

  1. Youtube
  2. Facebook
  3. Instagram

My question is while fetching them on front end I want to findo out whether my content has an embed, if so which of the following is embedded. (iframe presence checking is one (dirty)way still it own work for 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>

Above code works fine for youtube, but does not work for instagram coz when inserting instagram comes as blockquote tags,but if you echo them it will be straight away become iframe tags due to the script in it.

  • 写回答

1条回答 默认 最新

  • dousenjue3214 2017-01-30 13:50
    关注

    I would go for something like this:

    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;
    });
    

    I'm not sure how your embeds look like, you are talking about iframes to. So you need to find some identifiers that you can check.

    Your post probably got downvoted because it could have some more information?

    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类