In this tutorial you will learn how to use the WordPress excerpts in your custom theme that you can created anytimes that you like. In addition to the excerpt itself, we’ll add links to excerpts that can be seen on various WordPress-based sites and see how to customize the “Read More” text.
I’ve already looked at how to use excerpts on the archive page, but what about the main blog post? When a visitor arrives at your site, you cannot display the full content of the article on your first page. This is especially true if you have a blog post with a lot of content.
Let’s take a look at the different ways you can use WordPress Excerpts to solve this problem.
Blog Posts with no Excerpt
There is no Excerpts feature added to the post or topic yet. So, when a visitor views our site, they can see the full content of each message at once. It doesn’t really matter now, as the example post is simple and short. However, consider a case where you typically show 5 or more posts on your home page.
What if every post were a large 2000 word article? At this point, you will download 10,000 words of content in addition to the images and media contained in this post. It’s not perfect. Let’s take a look at what a training WordPress site looks like without excerpts.
Adding an excerpt with “Edit Post”
- You can use the Text Editor
- Or you can use the Visual Editor
After making all the necessary changes to the message using a text or visual editor, you can click “Update” to apply the changes.
Customize Excerpt anchor text
Is there a way to change this text? Actually there is! You can change the passage to “Check it out!” How can i do this? We can pass the arguments to the_content() function inside theme file to modified and you can open or edit index.php file.
Check this out
Display only an excerpt with the_excerpt() on all posts
It is now very easy to add read links to your posts through the WordPress editor. You might think this is great, but I don’t think I need to do this for every blog post I write. Worse, you already have hundreds of posts and now you’ll want to use this Excerpts technique for all of them. Do not be afraid, the_excerpt() function is located here.
To do this, replace the_content() function in index.php with the_excerpt(). This will limit the text to 55 words for each message, then […] to indicate that you may have more. By default, no link is created. We can see it in action right here.
Custom text to use WordPress Excerpts
When using the_excerpt() function, it uses the first 55 words of the message itself as an excerpt. You might not know that you can actually use your own text for passages. This text may not appear in the message itself, but you can use it if you like. The first thing you need to do is turn on the shutter option in the options on the screen to edit the post.
When this feature is enabled, Excerpt is an optional summary of the content available in the topic. Learn more about manual exposure. Let’s go ahead and set up our own text for the Excerpts box.
Only posts with custom passages will use custom text. Other posts still use Excerpts, but WordPress uses the first 55 words of the blog post to fill in the Excerpts in this case.
Adding single.php to your theme
Now there are some problems due to changes in index.php file. If you only have an index.php file, that file will be used to output the html when you click the homepage and blog posts itself to view only those blog posts.
Now I have changed the index.php file, removed the_content() function and replaced it with the_excerpt() function. Do you see this as a problem? Yes, as it is. You can only view excerpts by clicking on individual blog posts. This is not what we are looking for.
If so, what’s the solution? In this case, I want the index.php file to continue using the_excerpt() function while creating a new file for single.php that uses the_content() function. If you follow, you can create this markup and add it to your single.php file.
Adding Read More links to […]
The the_excerpt() function is very handy, but when I manually add the more tag in the WordPress editor, I lose the actual inserted hyperlink […] If you want to include symbolic links, you can use get_the_excerpt() and the_permalink() to set the link. Check the highlighted code in your index.php file.
It now includes all posts showing excerpts and actual hyperlinks that you can click to Read More.
Customize the Excerpt length
The default of 55 words may not work as expected with some themes. How can I customize the number of words used in a passage? To do this, you need to add the function to your functions.php file. Here’s how to do it:
WordPress uses the concept of hooks, which you can almost think of as events. This is how I say WordPress, I really want something else to happen when this event happens. This is basically what I did in this Excerpts.
When wordpress fires the’excerpt_length ‘event, you need to run a special function called customize_the_excerpt_length(). I hope you understand. Complete Hook Guide Coming Soon. The section length is now displayed as 30 words.
WordPress Excerpts summary
Use excerpts from your WordPress theme to provide summary information, such as information on many posts, allowing users to jump to the details they want. In this guide, we’ve covered most of the different ways to use Excerpts and customize them in your WordPress theme.
You learned how to manually create links to additional information for individual posts using a text editor and visual editor WordPress. We then looked at how to customize the anchor text of a WordPress generated link with a custom text string passed to the_content() function.
There we saw how to use the_excerpt() function and how to create a custom text Excerpts from the wordpress display options. I also added a link using the get_the_excerpt() and the_permalink() functions together. Finally, we learned how to change the default length of 55 words to the number of our choice. I think so for an excerpt from wordpress! Well done!
On my daily job, I am a software engineer, programmer & computer technician. My passion is assembling PC hardware, studying Operating System and all things related to computers technology. I also love to make short films for YouTube as a producer. More at about me…