可以使用WordPress的the_content过滤器,在文章内容输出前对文章内容进行处理,将所有code标签替换为pre标签。下面是具体的代码示例:
function replace_code_with_pre($content) {
$content = str_replace('\<code\>', '\<pre\>', $content);
$content = str_replace('\<\/code\>', '\<\/pre\>', $content);
return $content;
}
add_filter('the_content', 'replace_code_with_pre');
将上述代码添加到主题的functions.php文件中即可实现将所有code标签替换为
pre标签。需要注意的是,如果文章中存在其他的code标签,也会被替换为pre
标签,需要根据实际情况进行调整。
除特别注明外,本站所有文章均为[果博]原创 » 转载请注明出处来自https://aiguor.com/notes/261.html
果博