WordPress 人性化(?)的回覆按鈕

前端文章|2016.3.26.0218

WordPress 預設的回覆按鈕僅使用「回覆」作為文字顯示,缺少了一種「讓使用者互相對話」的感覺。有鑑於此,Ramm Dev 便設計出簡單的 snippet ,修改 WP 內建的回覆文字,於後增加發表該迴響的網友暱稱,藉此讓網站更具人性化。


原始修改資料來自 https://raam.org/2013/personalizing-the-wordpress-comment-reply-link/
The original idea belongs to Raam Dev (https://raam.org/2013/personalizing-the-wordpress-comment-reply-link/).
I am just a scripts kid fooling around. If offended. please let me know.

在佈景主題的functions.php新增以下程式碼

[php]/*
* 將「回覆」二字改為「回覆給」
*/
function add_comment_author_to_reply_link($link, $args, $comment){
$comment = get_comment( $comment );
// 若為匿名使用者,則使用「無名氏」作為回覆者姓名
if ( empty($comment->comment_author) ) {
if (!empty($comment->user_id)){
$user=get_userdata($comment->user_id);
$author=$user->user_login;
} else {
$author = __(‘Anonymous’);
}
} else {
$author = $comment->comment_author;
}
// 若網友輸入姓名含空格,則以空格前字串表述
if(strpos($author, ‘ ‘)){
$author = substr($author, 0, strpos($author, ‘ ‘));
}
// 修改「回覆」文字為「回覆給」
$reply_link_text = $args[‘reply_text’];
$link = str_replace($reply_link_text, ‘Reply to ‘ . $author, $link);
return $link;
}
add_filter(‘comment_reply_link’, ‘add_comment_author_to_reply_link’, 10, 3);
[/php]

標籤: ,

說些什麼吧

XHTML: 你可以使用以下標籤: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

沒有迴響