🚀 Is building a website too difficult? Let me guide you step by step—Learn about the 「Naibabiji WordPress Website Building Coaching Service」 →

Method to Display a „Read More“ Button for Posts on the WordPress Homepage

Friends new to WordPress will definitely discover a problem: when visiting the website homepage, your post content is displayed in full by default. This is not ideal for the browsing experience. If automatic excerpts or text truncation are used on the homepage, followed by aRead More/Continue Readingbutton, the browsing experience will be much better, as shown in the figure below:使用自动摘要前

???? Before using automatic excerpt, ???? After using automatic excerpt

使用自动摘要后So how to implement WordPress automatic excerpt and text truncation display? Naiba introduces three methods here. Method one and method three are suitable for novice users, while method two is suitable for users with a PHP foundation.

Method 1: Using the More Tag

More标签 more标签This is the most native method, but when writing posts, you need to manually insert a more tag once. It's not very practical for websites that already have many posts. New websites can adopt this method; it's a good habit. Usage of the more tag: when creating a new post in the WordPress Admin Dashboard, select the text in the editor yourself (Figure 1), then insert 'more'. You can also insert it by directly clicking the more tag in the visual editor (Figure 2).Note: The above two figures show the effect within the Classic Editor, you need todisable the new WordPress editorto use it.

Method 2: Code Modification

Code modification might be a bit challenging for novice friends. If you are using the Twenty Fifteen theme that Naiba previously used, just modify the code in these two files. Open the index.php and archive.php files in the /wp-content/themes/twentyfifteen/ directory with an editor and find the following code:
get_template_part( 'content', get_post_format() );
Replace with the following code:
get_template_part( 'content-search', get_post_format() );
Essentially, change 'content' to 'content-search' in this code within these two files. If you are not using my theme, you need to search for the 'the_content' field in your theme files yourself, then modify that segment of PHP code to
<?php
     if(!is_single()) 
	 { 
	the_excerpt();
		 } 
	else {
	the_content(__('(more…)')); 
	} 
?>
This method is not suitable for friends without a web development foundation because the location and content of 'the_content' vary across different themes. If modified incorrectly, the website may not open. So if you are going to modify it, remember to back up the modified files first and restore them if problems occur.

Method 3: Installing an Automatic Excerpt Plugin

WP-UTF8-Excerpt插件设置The WordPress automatic excerpt plugin recommended here isWP-UTF8-Excerpt, download address:https://wordpress.org/plugins/wp-utf8-excerpt/Main features: 1. Supports multi-byte languages (such as Chinese), will not produce garbled characters. 2. Excerpts can retain formatting tags from the post, such as fonts, colors, links, images, etc. (tags to retain can be set in the backend). 3. Different word counts can be set for the homepage and archive pages (default is 300 words per post on the homepage, 150 words per post on archive pages). The priority for excerpt display is as follows: 1. If the user manually sets an excerpt, display the manually set excerpt, regardless of word count and tags. 2. If the user manually sets <!–more–>, output the part before <!–more–>, regardless of word count and tags. 3. In other cases, display the excerpt according to the user-set word count and allowed tags. Reminder: Installing too manyWordPress pluginsmay cause the website to open slowly.NaibabijiCurrently, there are 13 active plugins.

How to set excerpt content for posts?

In terms of user experience, the effect of automatic truncation is not as good as displaying an excerpt. So, how do you set an excerpt for a Post? The method is as shown in the figure below:显示摘要框In the Post editing interface, click the 'Screen Options' in the upper right corner, then check 'Excerpt'. Next, you will see the excerpt box below the Post editor. Enter the excerpt there.WordPress Beginner Tutorial 2: How to Publish a Post

Modification method for the Twenty Twelve theme

Naibabiji currently uses the Twenty Twelve Theme. Recording the modification method here. Modify line 40 of the content.php file, replacing the content with the code below.
<?php if ( is_home() || is_category() || is_archive() || is_search() ) : // Only display Excerpts for Search ?>

🚀 Still feeling confused after reading the tutorial? Let me guide you step-by-step.

「Naibabiji WordPress Website Building Coaching Service」—From choosing a domain and buying hosting, to installing a Theme and publishing content, I「ll coach you through every step, helping you avoid detours and reach your goal directly.

👉 Learn about the Website Building Coaching Service
🔒

Comments are closed

The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.

×
二维码

Scan QR Code to Follow

AI Website Building Assistant

🤖
Hello! I am the Naibabiji AI Assistant. How can I help you?
Quick Consultation: