【发布时间】:2021-03-07 15:02:22
【问题描述】:
好的,所以我已经设法使它适用于 the_content,方法是在 functions.php 中添加这一行:
add_filter('the_content', 'my_hashcash_class');
function my_hashcash_class($content){
$content = preg_replace('/(\$|#)(\w+)[^\w".;]/s', '<a href="https://www.mywebsite.com/?s=\2">\1\2</a> ', $content);
return $content;
}
以上代码与 WordPress 过滤器 the_content 完美配合
但是,当我尝试使用 the_comments 对 cmets 执行相同操作时,我收到了一个错误:
There has been a critical error on this website.
Learn more about debugging in WordPress.
评论甚至不显示。
这是我的 cmets 代码:
add_filter('the_comments', 'my_hashcash_comments_class');
function my_hashcash_comments_class($comments){
$comments = preg_replace('/(\$|#)(\w+)[^\w".;]/s', '<a href="https://www.mywebsite.com/?s=\2">\1\2</a> ', $comments);
return $comments;
}
也许 WordPress 正在尝试对评论者用户名、头像和所有其他内容应用过滤器。
我希望过滤器仅应用于评论内容本身。
任何帮助将不胜感激。
谢谢。
【问题讨论】:
-
请分享 the_cmets 代码。
-
用_cmets 代码更新。
-
看到复数词
$comments我想知道它是不是一个数组而不是一个字符串? the_comments()