首页 > 解决方案 > 如何用 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>

标签: phpwordpresswordpress-theming

解决方案


推荐阅读