Some WordPress articles can be seen after comments / replies

If we want to hide part of the content of the article and need the user’s comments and replies to be visible, today’s WordPress tutorial article is just right for you.

This function is easy to implement, and can improve the enthusiasm of users, is a very good function.

Here is the main core code.

//WordPressIt can be seen from the comments of part of the article

function reply_to_read($atts, $content=null) {   
	extract(shortcode_atts(array("notice" => '<p class="reply-to-read">reminder: The content here needs<a href="#respond" rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  rel="external nofollow"  title="Comment on this article">Comment on this article</a>You can't view it until you have finished.</p>'), $atts));   
	$email = null;   
	$user_ID = (int) wp_get_current_user()->ID;   
	if ($user_ID > 0) {   
		$email = get_userdata($user_ID)->user_email;   
		//Display content directly to bloggers   
		$admin_email = ""; //Blogger Email   
		if ($email == $admin_email) {   
			return $content;   
	} else if (isset($_COOKIE['comment_author_email_' . COOKIEHASH])) {   
		$email = str_replace('%40', '@', $_COOKIE['comment_author_email_' . COOKIEHASH]);   
	} else {   
		return $notice;   
	if (empty($email)) {   
		return $notice;   
	global $wpdb;   
	$post_id = get_the_ID();   
	$query = "SELECT `comment_ID` FROM {$wpdb->comments} WHERE `comment_post_ID`={$post_id} and `comment_approved`='1' and `comment_author_email`='{$email}' LIMIT 1";   
	if ($wpdb->get_results($query)) {   
		return do_shortcode($content);   
	} else {   
		return $notice;   

add_shortcode('reply', 'reply_to_read');

usage method

1. First, add the following code to the functions.php It’s in the file.

2. Then add one of the following two ways when editing the article to hide part of the content of the article.

The end result is the following

reminder: The content here needsComment on this articleYou can't view it until you have finished.

It will be displayed after reply

Related Article
Two methods of automatically renaming uploaded files in WordPress

When we edit and publish articles, we often upload some pictures, audio and other files. Interested webmasters will find that Read more

WordPress tutorial: adding author filtering options to the background article list

When there are multiple users publishing articles in our site, in order to facilitate the administrator to view the article Read more

WordPress displays the registration time of the login user in the frontend

When using WordPress to build a website, some users want to display the user registration time in the frontend, but Read more

WordPress adds the number of SQL queries at the bottom

An excellent woodpress theme is definitely that the less SQL consulting is used, the better. How can we see how Read more

Leave a Reply

Your email address will not be published. Required fields are marked *

To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image