{"id":1080,"date":"2018-01-26T09:26:55","date_gmt":"2018-01-26T09:26:55","guid":{"rendered":"https:\/\/firstsiteguide.com-excerpts\/"},"modified":"2023-10-04T09:25:08","modified_gmt":"2023-10-04T09:25:08","slug":"wordpress-excerpts","status":"publish","type":"post","link":"https:\/\/firstsiteguide.com\/wordpress-excerpts\/","title":{"rendered":"How to Control Excerpts in WordPress","gt_translate_keys":[{"key":"rendered","format":"text"}]},"content":{"rendered":"
An excerpt is a post summary that is being used to describe your article in a few short sentences. Those descriptions are a great way of letting your visitors see what\u2019s the post about and decide if they\u2019re interested in reading the rest of it before clicking the button. Also, it is an excellent tool for RSS readers.<\/p>\n\n\n\n
In WordPress, excerpts can be manual or automatic, and they\u2019re slightly different from teasers (text before <–more–> tag) just because WordPress is handling them differently. If you don\u2019t write your own excerpt, WordPress will make a summary automatically and take first 55 words from your post.<\/p>\n\n\n\n
In this article, we are about to show you how to control excerpts in WordPress. <\/p>\n\n\n\n
If you are new to WordPress<\/a> and now you\u2019re trying to find your own excerpt box where you want to write a manual summary, you have probably found none. That\u2019s because excerpts are hidden by default. To make the textbox visible, while you are editing a post or writing a new one, click on \u201cScreen Options\u201d<\/em> which can be found on top of the page where you have to check \u201cExcerpts\u201d. Now you\u2019re ready to scroll under your post and write your excerpt.<\/p>\n\n\n\n But as you can see, there is no option which would simply change the length of an excerpt. That\u2019s probably one of the reasons why you\u2019re reading this article, and in the next few lines, we\u2019re about to show you a quick and simple way of doing that.<\/p>\n\n\n\n Of course, you are free to change the number to any integer you want. But remember we\u2019re talking about summaries \u2013 you don\u2019t want your summary to be too short, but there\u2019s no need for exaggerating. You can always put a “read more” link<\/a> after each excerpt.<\/p>\n\n\n\n If you want even more control over your excerpts, you should consider Advanced Excerpt plugin<\/a> which is capable of doing the same job with some extra features, plus, you won\u2019t have to deal with the code and PHP files.<\/p>\n\n\n\n After some time spent on your WordPress blog<\/a>, some categories might require more words in excerpts and some will need shorter ones. So, let us show you how to change the length of the category excerpt.<\/p>\n\n\n\n The first example will let you choose one category for which you want to set a different excerpt length. Select that category, define the number of words for its excerpt and the number of words for all other categories\u2019 excerpt:<\/p>\n\n\n\n While this will be more than enough in order to change excerpt length for that one category that bothers you, it won\u2019t help you much if you need to define the length for several categories at once<\/strong>. In that case, you will be needing the following:<\/p>\n\n\n This function will allow you to set different excerpt lengths for different categories and still let you choose the default one.<\/p>\n\n\n\n Instead of displaying the entire post on your homepage, excerpts allow you to show only a part of it which can make the user interested in the article.<\/p>\n\n\n\n After users see the title, image, and an excerpt of your post, you need to inform them that they can read more about the topic by following the link to your article. If you ask us, a featured image<\/a> should always lead to the main article, but you should also allow your readers to follow the \u201cRead More\u201d link or a button.<\/p>\n\n\n\n
function my_excerpt_length($length) {
return 110;
}
add_filter('excerpt_length', 'my_excerpt_length');<\/pre>\n\n<\/div>\n\n\n<\/pre>\n\n\n\n
\n
Change default excerpt length for different categories<\/h2>\n\n\n\n
\n
function excerpt_length_category( $length ) {\nif ( in_category( 'Reviews' ) ) {\nreturn 20;\n} else {\nreturn 60;\n}\n}\nadd_filter( 'excerpt_length', \n'excerpt_length_category' );<\/pre>\n\n<\/div>\n\n\n
<\/pre>\n\n\n\n
\n
function excerpt_length_category( $length ) {\nif ( in_category( 'Review' ) ) {\nreturn 35;\n} elseif ( in_category( array( 'News', \n'Videos', 'Editorial' ) ) ) {\nreturn 60;\n} else {\nreturn 55;\n}\n}\nadd_filter( 'excerpt_length', \n'excerpt_length_category' );<\/pre>\n\n<\/div>\n\n\n
<\/pre>\n\n\n\n
Add a “Read More” link to the end of an excerpt<\/h2>\n\n\n\n