How to modify the length of the excerpt in WordPress

If you use the popular WordPress editorial system for your blog, you might be aware that it provides two options for displaying articles on the homepage. You can either show only an excerpt of the article or display the entire article. The choice is yours. In WordPress, we refer to the excerpt as ‘excerpt,’ and by default, WordPress limits it to the first 55 words. This means that on the homepage, you’ll see the article’s image, the first 55 words, and then a ‘read more’ link. Today, we’ll focus on how to modify the length of the excerpt in WordPress. Let’s explain it.

Jak upravit délku výňatku článku ve WordPressu

How to modify the length of the excerpt in WordPress

To achieve this without installing additional plugins, we’ll use a code snippet and the popular WPCode plugin, which everyone who wants to modify the properties and behavior of their WordPress website should have installed. A snippet is nothing more than a short piece of code in PHP or another language that modifies the properties and behavior of a website.

Installing the WPCode Plugin

To insert codes into your website, you have two options. You can hardcode the code into the appropriate file or use a plugin that dynamically injects parts of the code into your site. The latter option is better for one simple reason: it’s more secure, and your code won’t get erased with each update that overwrites the file containing your code.

Here’s how to install the WPCode plugin:

  1. Click on ‘Plugins‘ in the left menu.
  2. Select ‘Add New‘ from the submenu.
  3. In the upper-right corner, notice the search field.
  4. Type ‘WPCode‘ into the search field.
  5. Once WordPress finds the plugin, install and activate it.

If you’re interested in a complete article where I describe working with this plugin, you can find it here: How to insert custom codes into WordPress 

How to modify the length of the excerpt in WordPress using snippet

Using the WPCode plugin, insert this short code into your website:

				
					function new_excerpt_length($length) {
return 100;
}
add_filter('excerpt_length', 'new_excerpt_length');
				
			

This code adjusts the length of the excerpt from the original 55 words to 100. If, for any reason, this number doesn’t suit you, simply modify the ‘return’ value in the code to a different number.

Conclusion

Once you insert this snippet into your website, WordPress will automatically adjust the excerpt length to the number of words you desire. This allows you to either shorten or extend the excerpt. It’s up to you. This method is entirely safe and shouldn’t disrupt any existing functionalities or the appearance of your website. If you’re unsatisfied with the change, you can easily deactivate or remove the snippet altogether.

The website is created with care for the included information. I strive to provide high-quality and useful content that helps or inspires others. If you are satisfied with my work and would like to support me, you can do so through simple options.

Byl pro Vás tento článek užitečný?

Klikni na počet hvězd pro hlasování.

Průměrné hodnocení. 0 / 5. Počet hlasování: 0

Zatím nehodnoceno! Buďte první

Jak užitečný vidíte tento článek.

Sledujte mě na sociálních médiích.

Je mi líto, že pro Vás nebyl článek užitečný.

Jak mohu vylepšit článek?

Řekněte mi, jak jej mohu zlepšit.

newsletter

Subscribe to the Newsletter

Stay informed! Join our newsletter subscription and be the first to receive the latest information directly to your email inbox. Follow updates, exclusive events, and inspiring content, all delivered straight to your email.

Odebírat
Upozornit na
guest
0 Komentáře/ů
Vložené zpětné vazby.
Zobrazit všechny komentáře.

Pokud mi chcete napsat rychlou zprávu, využije, prosím, níže uvedený
kontaktní formulář. Děkuji.

Další Kontaktní údaje