Digital Marketing

Hướng dẫn thêm User Role Label cạnh tên người comment trong WordPress

Hướng dẫn thêm User Role Label cạnh tên người comment trong WordPress

Nhãn vai trò người dùng bên cạnh tên của người bình luận trong WordPress

Tiếp tục với trò chơi đổi tên, trong bài viết này, Hocban.vn chia sẻ đến các bạn cách: thêm Nhãn vai trò người dùng bên cạnh tên người bình luận (comment) trong WordPress.

Cách thêm Nhãn vai trò người dùng bên cạnh tên của người bình luận trong WordPress

Sẽ rất nhanh, nó gồm 3 bước dưới đây, các bạn làm cẩn thận vì nó đang chèn code vào theme.

  • Bước 1: Sao chép và dán đoạn mã sau vào cuối tệp function.php của chủ đề.
if ( ! class_exists( 'WPB_Comment_Author_Role_Label' ) ) :
class WPB_Comment_Author_Role_Label {
public function __construct() {
add_filter( 'get_comment_author', array( $this, 'wpb_get_comment_author_role' ), 10, 3 );
add_filter( 'get_comment_author_link', array( $this, 'wpb_comment_author_role' ) );
}

// Get comment author role 
function wpb_get_comment_author_role($author, $comment_id, $comment) { 
$authoremail = get_comment_author_email( $comment); 
// Check if user is registered
if (email_exists($authoremail)) {
$commet_user_role = get_user_by( 'email', $authoremail );
$comment_user_role = $commet_user_role->roles[0];
// HTML output to add next to comment author name
$this->comment_user_role=" <span class="comment-author-label comment-author-label-".$comment_user_role.'">' . ucfirst($comment_user_role) . '</span>';
} else { 
$this->comment_user_role="";
} 
return $author;
} 

// Display comment author 
function wpb_comment_author_role($author) { 
return $author .= $this->comment_user_role; 
} 
}
new WPB_Comment_Author_Role_Label;
endif;
  • Bước 2: Vào Tùy chỉnh >> CSS bổ sung >> dán đoạn CSS bên dưới vào đó và lưu lại để xem kết quả.
.comment-author-label {
padding: 5px;
font-size: 14px;
border-radius: 3px;
}

.comment-author-label-editor { 
background-color:#efefef;
}
.comment-author-label-author {
background-color:#faeeee;
}

.comment-author-label-contributor {
background-color:#f0faee; 
}
.comment-author-label-subscriber {
background-color:#eef5fa; 
}

.comment-author-label-administrator { 
background-color:#fde9ff;
}

Rất nhanh chóng và đơn giản phải không? Tuy nhiên, mình nhắc lại với các thao tác chèn code trực tiếp vào theme thì các bạn phải cẩn thận, làm từ từ nếu chưa quen, kẻo hỏng theme, hỏng web thì khổ.

À, giờ đến buổi giao lưu, nếu bạn nào đã sử dụng thủ thuật này thì hãy comment bên dưới để cùng trao đổi và học hỏi thêm về thủ thuật này nhé, xin cảm ơn!

Bài viết liên quan

  • Thêm Huy hiệu bên cạnh tên Quản trị viên khi nhận xét về WordPress bằng CSS
  • Đếm số lượng bình luận của mỗi người, số lượng bình luận của người dùng trên WordPress

4.1 / 5 – (18 phiếu bầu)


Marketing online


Thông tin thêm

Hướng dẫn thêm User Role Label cạnh tên người comment trong WordPress

#Hướng #dẫn #thêm #User #Role #Label #cạnh #tên #người #comment #trong #WordPress
[rule_3_plain] #Hướng #dẫn #thêm #User #Role #Label #cạnh #tên #người #comment #trong #WordPress

User Role Label cạnh tên người comment trong WordPress
Tiếp tục với trò đổi tên thì trong bài này, Hocban.vn chia sẻ đến bạn cách để: thêm User Role Label cạnh tên người comment (bình luận) trong WordPress.
MỤC LỤC NỘI DUNG1 Hướng dẫn cách thêm User Role Label cạnh tên người comment trong WordPress2 Bài viết liên quan
Hướng dẫn cách thêm User Role Label cạnh tên người comment trong WordPress
Sẽ rất nhanh thôi, nó bao gồm 3 bước dưới đây, bạn thực hiện cẩn thận nhé vì nó là chèn code vào theme.

Bước 1: Bạn copy và dán đoạn code sau vào dưới cùng của file function.php của theme đang dùng.

if ( ! class_exists( ‘WPB_Comment_Author_Role_Label’ ) ) :
class WPB_Comment_Author_Role_Label {
public function __construct() {
add_filter( ‘get_comment_author’, array( $this, ‘wpb_get_comment_author_role’ ), 10, 3 );
add_filter( ‘get_comment_author_link’, array( $this, ‘wpb_comment_author_role’ ) );
}

// Get comment author role
function wpb_get_comment_author_role($author, $comment_id, $comment) {
$authoremail = get_comment_author_email( $comment);
// Check if user is registered
if (email_exists($authoremail)) {
$commet_user_role = get_user_by( ’email’, $authoremail );
$comment_user_role = $commet_user_role->roles[0];
// HTML output to add next to comment author name
$this->comment_user_role=” <span class=”comment-author-label comment-author-label-“.$comment_user_role.'”>’ . ucfirst($comment_user_role) . ‘</span>’;
} else {
$this->comment_user_role=””;
}
return $author;
}

// Display comment author
function wpb_comment_author_role($author) {
return $author .= $this->comment_user_role;
}
}
new WPB_Comment_Author_Role_Label;
endif;

Bước 2: Vào Customize >> Additional CSS >> dán đoạn CSS dưới đây vào trong đó rồi lưu lại để xem kết quả.

.comment-author-label {
padding: 5px;
font-size: 14px;
border-radius: 3px;
}

.comment-author-label-editor {
background-color:#efefef;
}
.comment-author-label-author {
background-color:#faeeee;
}

.comment-author-label-contributor {
background-color:#f0faee;
}
.comment-author-label-subscriber {
background-color:#eef5fa;
}

.comment-author-label-administrator {
background-color:#fde9ff;
}
Rất nhanh và đơn giản đúng không nào ? Tuy nhiên mình nhắc lại là với những thao tác chèn code trực tiếp vào theme thì bạn phải cẩn thận, làm từ từ nếu không rành, kẻo lại hỏng theme, hỏng web thì khổ.
Rồi, bây giờ đến đoạn giao lưu, anh em nào có xài qua thủ thuật này mời comment bên dưới để giao lưu học hỏi thêm về mẹo này nhé, cảm ơn anh em !
Bài viết liên quan

Thêm huy hiệu bên cạnh tên Admin khi bình luận trên WordPress đơn giản với CSS
Đếm số bình luận của mỗi người, user comment count trên WordPress

4.1/5 – (18 votes)

window.addEventListener(‘DOMContentLoaded’, function() {
jQuery(document).ready(function( $) {
$.post( ‘https://hocban.vn/wp-admin/admin-ajax.php’, {action: ‘mts_view_count’, id: ‘9115’});
});
});
#Hướng #dẫn #thêm #User #Role #Label #cạnh #tên #người #comment #trong #WordPress
[rule_2_plain] #Hướng #dẫn #thêm #User #Role #Label #cạnh #tên #người #comment #trong #WordPress
[rule_2_plain] #Hướng #dẫn #thêm #User #Role #Label #cạnh #tên #người #comment #trong #WordPress
[rule_3_plain]

#Hướng #dẫn #thêm #User #Role #Label #cạnh #tên #người #comment #trong #WordPress

User Role Label cạnh tên người comment trong WordPress
Tiếp tục với trò đổi tên thì trong bài này, Hocban.vn chia sẻ đến bạn cách để: thêm User Role Label cạnh tên người comment (bình luận) trong WordPress.
MỤC LỤC NỘI DUNG1 Hướng dẫn cách thêm User Role Label cạnh tên người comment trong WordPress2 Bài viết liên quan
Hướng dẫn cách thêm User Role Label cạnh tên người comment trong WordPress
Sẽ rất nhanh thôi, nó bao gồm 3 bước dưới đây, bạn thực hiện cẩn thận nhé vì nó là chèn code vào theme.

Bước 1: Bạn copy và dán đoạn code sau vào dưới cùng của file function.php của theme đang dùng.

if ( ! class_exists( ‘WPB_Comment_Author_Role_Label’ ) ) :
class WPB_Comment_Author_Role_Label {
public function __construct() {
add_filter( ‘get_comment_author’, array( $this, ‘wpb_get_comment_author_role’ ), 10, 3 );
add_filter( ‘get_comment_author_link’, array( $this, ‘wpb_comment_author_role’ ) );
}

// Get comment author role
function wpb_get_comment_author_role($author, $comment_id, $comment) {
$authoremail = get_comment_author_email( $comment);
// Check if user is registered
if (email_exists($authoremail)) {
$commet_user_role = get_user_by( ’email’, $authoremail );
$comment_user_role = $commet_user_role->roles[0];
// HTML output to add next to comment author name
$this->comment_user_role=” <span class=”comment-author-label comment-author-label-“.$comment_user_role.'”>’ . ucfirst($comment_user_role) . ‘</span>’;
} else {
$this->comment_user_role=””;
}
return $author;
}

// Display comment author
function wpb_comment_author_role($author) {
return $author .= $this->comment_user_role;
}
}
new WPB_Comment_Author_Role_Label;
endif;

Bước 2: Vào Customize >> Additional CSS >> dán đoạn CSS dưới đây vào trong đó rồi lưu lại để xem kết quả.

.comment-author-label {
padding: 5px;
font-size: 14px;
border-radius: 3px;
}

.comment-author-label-editor {
background-color:#efefef;
}
.comment-author-label-author {
background-color:#faeeee;
}

.comment-author-label-contributor {
background-color:#f0faee;
}
.comment-author-label-subscriber {
background-color:#eef5fa;
}

.comment-author-label-administrator {
background-color:#fde9ff;
}
Rất nhanh và đơn giản đúng không nào ? Tuy nhiên mình nhắc lại là với những thao tác chèn code trực tiếp vào theme thì bạn phải cẩn thận, làm từ từ nếu không rành, kẻo lại hỏng theme, hỏng web thì khổ.
Rồi, bây giờ đến đoạn giao lưu, anh em nào có xài qua thủ thuật này mời comment bên dưới để giao lưu học hỏi thêm về mẹo này nhé, cảm ơn anh em !
Bài viết liên quan

Thêm huy hiệu bên cạnh tên Admin khi bình luận trên WordPress đơn giản với CSS
Đếm số bình luận của mỗi người, user comment count trên WordPress

4.1/5 – (18 votes)

window.addEventListener(‘DOMContentLoaded’, function() {
jQuery(document).ready(function( $) {
$.post( ‘https://hocban.vn/wp-admin/admin-ajax.php’, {action: ‘mts_view_count’, id: ‘9115’});
});
});

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *

Back to top button