我正在尝试将我网站上某些单词的颜色改为红色。然而,下面的代码将每个单词改为“array”。
有人能告诉我我的代码有什么问题吗?
function replace_content($content)
{
$newwords = array("Check", "Map", "Comments", "Send", "Print");
$content = str_replace($newwords, \'<span style="color:red">\' . $newwords . \'</span>\', $content);
return $content;
}
add_filter(\'the_content\',\'replace_content\');
SO网友:Brendan
function replace_content($text) {
$replace = array(
\'Check\' => \'<span style="color:red">Check</span>\',
\'Map\' => \'<span style="color:red">Map</span>\',
\'Comments\' => \'<span style="color:red">Comments</span>\',
\'Print\' => \'<span style="color:red">Print</span>\'
);
$text = str_replace(array_keys($replace), $replace, $text);
return $text;
}
add_filter(\'the_content\',\'replace_content\');