Replace text in excerpt

时间:2013-06-29 作者:Incognita Mundi

我的自定义WP安装有一个单独的主题,将用于移动用户,在我的情况下,我需要在所有摘录实例中更改html标记,但在不更改DB的情况下,我发现这个简单的功能非常完美,但我无法使其工作,什么都没有发生。

function replace_content_on_the_fly($text){
$replace = array(
    // \'words to find\' => \'replace with this\'
    \'<p>\' => \'<div>\',
    \'</p>\' => \'</div>\'
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
}
add_filter(\'the_excerpt\', \'replace_content_on_the_fly\');
我在我的主题中添加了上述代码function.php. 为什么不起作用?

1 个回复
SO网友:s_ha_dum

您可以在函数the_excerpt 已使用。当get_the_excerpt 已使用,其中does not apply the the_excerpt filter. 它适用于get_the_excerpt 相反

使用get_the_excerpt 将导致筛选器应用于这两种情况,因为the_excerpt() uses get_the_excerpt().

自动生成的摘录内容是另一回事,因为它是由a filter on get_the_excerpt 那个strips the markup.

结束

相关推荐

是否可以在激活Customfield‘CheckBox’时激活Customfield‘Text Description’?

我试图找到一个解决方案,当选择框被选中时,如何激活WordPress页面中的另一个自定义字段。这是只显示customfield的脚本\'checkbox\' 在wordpress页面编辑器中。array( \'name\' => \'Lees meer button\', \'desc\' => \'Leesbutton weergeven.\', \'id\' => $prefix . \'homepage_slider_leesme