php - 如何用 wordpress 函数中两个字符串之间的变量替换 wp-post 内容?
问题描述
我想要一个 wordpress 函数来替换 iframe src,例如:(http://my1stembed.tld/ variablestring .html )到(http://my2ndembed.tld/ variablestring .html )在 wordpress 发布内容中带有变量。我该怎么做呢。我需要这样的功能
function replace_content($content)
{
$content = str_replace('http://my1stembed.tld/', 'http://my2ndembed.tld/',$content);
return $content;
}
add_filter('the_content','replace_content');
上面的函数只是替换固定的,例如:(http://my1stembed.tld/)字符串到(http://my2ndembed.tld/)而不是变量。我是wordpress的新手,不知道。非常感谢任何帮助。
<iframe src="http://my1stembed.tld/embed/variablefilename/" width="640" height="360" frameborder="0" scrolling="no" allowfullscreen="allowfullscreen"></iframe>
至
<iframe src="http://my2ndembed.tld/embed/variablefilename/" width="640" height="360" frameborder="0" scrolling="no" allowfullscreen="allowfullscreen"></iframe>
解决方案
推荐阅读
- html - 如何选择除具有特定类的 div 内的元素之外的所有元素
- python - 未定义计划名称
- oracle - oracle first_Value解析函数有什么用?
- bash - 如何设置切换键以在执行期间显示 shell 脚本输出?
- android - 有没有办法通过 adb 从 USB 连接的 android 设备连接到 docker 容器?
- javascript - 模拟模块中除一个功能之外的所有功能
- jenkins - 从 Jenkins 作业 DSL 脚本中访问 Jenkins 凭据绑定
- vue.js - nuxt.js:有没有办法在页面刷新时阻止对服务器的请求
- java - 映射异常:找不到具有逻辑名称的列
- swift - NSPopover 解雇不会将其从父级的presentedViewControllers(Xcode 11)中删除