【问题标题】:How to get the iframe url for specific domain in WordPress如何在 WordPress 中获取特定域的 iframe url
【发布时间】:2018-05-23 20:18:03
【问题描述】:

我的 WordPress 网站帖子有不同类型的 iframe 标签: 例如:

<iframe src="http://examplesite1.tld/somepageordirectory"></iframe>
<iframe src="http://examplesite2.tld/somepageordirectory"></iframe>
<iframe src="http://examplesite3.tld/somepageordirectory"></iframe>
<iframe src="http://examplesite4.tld/somepageordirectory"></iframe>

我需要 WordPress 函数来获取和替换指定域(例如:examplesite3.tld)的 iframe src,例如:

<iframe src="http://examplesite1.tld/somepageordirectory"></iframe>
<iframe src="http://examplesite2.tld/somepageordirectory"></iframe>
<iframe src="/embed.php?ref=http://examplesite3.tld/somepageordirectory"></iframe>
<iframe src="http://examplesite4.tld/somepageordirectory"></iframe>

我是 WordPress 新手。

非常感谢任何帮助,对我的英语感到非常抱歉。

【问题讨论】:

    标签: php html wordpress wordpress-theming


    【解决方案1】:

    我们需要周围的代码来理解页面是如何构建的,而不是显示的代码。

    要执行您所说的操作,您将使用周围的 html 标记并在其中回显 wordpress 变量,例如:

    <iframe src="<?php echo wp_function( 'variable' );?>"></iframe>
    

    【讨论】:

    • 因为我的网站有很多 iframe 标签,所以我需要任何可以作为查找和替换的 wordpress/php 函数,例如:function replace_content($content) { $content = str_replace('##Replace Me##', '##With Something Else##',$content); return $content; } add_filter('the_content','replace_content'); 但它只适用于固定字符串而不是变量。
    • 您可以为要替换链接的 iframe 设置一个类或 id 吗?如果可以,那么您可以轻松地做到这一点,无论是使用 php 还是在页面加载后使用 Javascript 进行 dom 替换。
    • 如果它在特定的 iframe 上,您可以遍历 iframe 标签的数量,但这很麻烦
    • 通过使用波纹管 wp 函数,我将能够动态地将 id 添加到指定的 iframe,例如:function replace_content($content) { $content = str_replace('src="http://examplesite3.tld', 'id="myembed" src="http://examplesite3.tld',$content); return $content; } add_filter('the_content','replace_content'); 现在我如何获取和替换服务器端的 url(wp 函数或 php)有问题?
    猜你喜欢
    • 2013-11-13
    • 1970-01-01
    • 1970-01-01
    • 2022-11-30
    • 2015-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多