这将阻止在添加到函数时显示尾随的非中断空格,而不会实际修改数据库中的帖子。php(或主题存储用户添加函数的任何地方)。
function trim_post_trailing_whitespace($content){
// use preg_replace to convert into an unused character "☺" (ALT 1)
// then use rtrim to remove trailing unused character(s) "☺"
// now use rtrim again to remove trailing whitespace
// now convert unused character(s) "☺" back into in case used elsewhere
// Return
$content = preg_replace("/ /", "☺", $content);
$content = rtrim($content, "☺");
$content = rtrim($content);
$content = preg_replace("/☺/", " ", $content);
return $content;
/* All the above simplified into a single equation
return preg_replace("/☺/", " ", rtrim(rtrim(preg_replace("/ /", "☺", $content), "☺")));
*/
}
add_filter(\'the_content\', \'trim_post_trailing_whitespace\', 0);
// The \'0\' priority means do this first.