自由屋推书网—热门的小说推荐平台!

你的位置: 首页 > wordpress分享

解决WordPress点击评论按钮页面评论框不跟随评论刷新

2022-01-07 15:44:46

近期在回复博友评论时发现评论框不跟随,点击评论按钮页面刷新的情况,这个体验实在是很差。我记得这个问题很早之前就出现过,也记得处理了,不知道为啥又莫名其妙的出现了。

主要是WordPress官方修改了该函数的输出结构,去掉了一个绑定的点击事件:

不管了本着面向百度开发的原则,找到了靠谱的代码

/**
* 修改评论回复按钮链接
*/
global $wp_version;
if (version_compare($wp_version, '5.1.1', '>=')) {
add_filter('comment_reply_link', 'theme_replace_comment_reply_link', 10, 4);
function theme_replace_comment_reply_link($link, $args, $comment, $post)
{
if (get_option('comment_registration') && !is_user_logged_in()) {
$link = sprintf(
'%s',
esc_url(wp_login_url(get_permalink())),
$args['login_text']
);
} else {
$onclick = sprintf(
'return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )',
$args['add_below'],
$comment->comment_ID,
$args['respond_id'],
$post->ID
);
$link = sprintf(
"%s",
esc_url(add_query_arg('replytocom', $comment->comment_ID, get_permalink($post->ID))) . "#" . $args['respond_id'],
$onclick,
esc_attr(sprintf($args['reply_to_text'], $comment->comment_author)),
$args['reply_text']
);
}
return $link;
}
}

编辑推荐

热门小说