更改由get_comments_link()和get_comments_pagenum_link()functions产生的注释链接

wordpress.stackexchange https://wordpress.stackexchange.com/questions/5679

目前我的主题要求 get_comments_link() 创建标准锚 #注释 链接到下面的评论, get_comments_pagenum_link() 在分页评论中起作用。

我想更换 #注释 在这些功能中使用任何其他字符串锚定,当然没有更改WP的Core PHP文件。

一个简单的 add_filter 完全替换核心功能(在Pluggable.php中除外)似乎是不可能的。还有其他方法可以实现核心函数的输出的微小变化,即使用PHP(而不是说Java)?这里有办法使用 add_filterstr_replace() 也许?

例如,这对于外语站点很有用,例如将评论重定向到另一页,例如,使用URL请求。

有帮助吗?

解决方案

因此解决方案 get_comments_pagenum_link() 功能足够简单:

add_filter('get_comments_pagenum_link' , 'new_get_comments_pagenum_link');
function new_get_comments_pagenum_link($content) {
    $content = str_ireplace('#comments' , '#other', $content);
    return $content;
}

哪个过滤了输出 get_comments_pagenum_link() 取代 #内容#其他, ,或您可能选择的任何其他字符串。

为了 get_comments_link() 函数,无法过滤,我只是发现我的WordPress主题已经在其自己的注释链接函数中使用,因此使用上面显示的相同方法过滤了此主题功能。

其他提示

对于功能 get_comments_link() 没有这样的过滤器。您可能需要使用一个称为的替代功能 get_comment_link() 有一个过滤器: get_comment_link.

对于功能 get_comments_pagenum_link() 存在一个过滤器: get_comments_pagenum_link.

要了解过滤器的工作方式,请参阅 插件API(WordPress法典). 。那里的信息应回答有关如何使用的所有问题 add_filter().

由于该链接是PHP中的字符串,因此您可以使用任何PHP字符串功能来定位,提取和替换内容。 PHP字符串功能的完整列表(PHP手册).

许可以下: CC-BY-SA归因
scroll top