How To Display Excerpt In WordPress Theme In Place Of Content?
August 27th, 2016 | by Ravi Chahar || 8 Comments |
In the previous post, I have mentioned how to add excerpt in WordPress from the admin area. There are many people who want to show the excerpt in place of the full content in their WordPress theme. You can do that by editing the theme file.
WordPress is an amazing platform and you can play with it. The WordPress themes consist the PHP codes and if you have a little bit of knowledge about PHP then you can change the theme functions.
What’s The Importance To Display Excerpt In WordPress?
You may have noticed that when you visit any website then there may be many posts with a few lines of description and then the read more button appears. It improves the user-experience.
It would help you to reduce bounce rate of your website because the people will engage more and like to see the archives page including the categories of your posts and more.
Instead of looking the whole content of every post, readers like to grab the description and then decide to read the full post.
Most of the WordPress theme developers prefer to add the excerpt in WordPress themes instead of showing the whole content. They provide the inbuilt feature to their users.
How To Add Excerpt in WordPress Theme?
When it comes to edit the theme files and then you should always backup the website and the database. It’s because sometimes a little piece of code can break your whole theme.
To add excerpt in WordPress theme, you have to edit the “index.php” file. There are a few steps to follow.
Step 1:- Login to your cPanel and open the file manager.
Step 2:- Search for the “wp-content” folder where all the plugins and folders are present.
Step 3:- There would be a folder with the name “Themes” in which you have to search for the name of the theme you are using.
Step 4:- Many files and folders would be there from which you have to right click on the “index.php“. Click on edit and the code will appear to you in a new tab.
Step 5:- If you are aware of the PHP coding then it won’t be so hard for you. But if are not tech savvy then just find a line of code.
Replace it with :-
Save the file and you are ready to go. You will see the excerpt has been added in your theme and from now onwards you don’t need to add the read more button manually. Your WordPress theme would pick it up.
This will display excerpt in WordPress blog page, not all other pages. If you want to edit the categories, search results then you have to add it in the “archive.php” which would let your theme to show the description with all the posts.
Every developer has his/her own style of writing the codes and if you are not aware of WordPress theme’s structure then it would be difficult.
But the simple thing is to change the code in the “index.php” file which would solve your problem for the blog post page.
Can You Add Excerpt In WordPress Theme Now?
Though it won’t be so hard to replace the code. You just have to find the file and paste the code mentioned above. It is the WordPress default feature to capture the description after adding the excerpt code.
Instead of showing the full content, you can add excerpt in WordPress posts and pages. There is another option which carries the brackets at the end of the excerpt. But for now, you don’t need to worry about that. If you still face any problem then feel free to ask.