How To Increase The Character Limit In The Excerpt In WordPress

Last updated December 6th, 2023 00:01

The term “excerpt” is probably new to many people. Let’s first briefly explain what it is. The excerpt is likely familiar to those who write blogs, but they may not be aware that this is the name for this WordPress feature. When writing a blog, you may have noticed that the articles are listed one after another on the main page, from newest to oldest. To avoid displaying the entire article on the main page, WordPress shows only a portion of it. Essentially, it displays a snippet of the article, and it is up to you whether you click the “read more” button to read the full content. This snippet of text is called an excerpt. Now, let’s see how to increase the character limit in the excerpt in WordPress using a short code. If you want the excerpts to be longer (or shorter), here’s the solution.

How to Increase the Character Limit in the Excerpt in WordPress

To be able to add short PHP codes, also known as snippets, to your website, you will need a plugin. There are several available in the official repository. Personally, I prefer the WPCode plugin. It can be found at this address: https://wordpress.org/plugins/insert-headers-and-footers/

Thanks to this plugin, you can easily add code to the system that will run and perform actions and functions defined by you. For detailed instructions on how to work with such a plugin if you haven’t done so before, you can find them here: How to Insert Custom Code in WordPress.

If you have read the article, you probably have an idea of how to add such a snippet to your website. The code for completely disabling comments looks like this:

				
					add_filter(
	'excerpt_length',
	function ( $length ) {
		// Number of words to display in the excerpt.
		return 40;
	},
	500
);
				
			

Jak snippet funguje?

Konkrétně tento snippet používá funkci add_filter(), která přidává filtr do systému WordPress. Filtr se nazývá excerpt_length, což je interní název filtru pro nastavení délky excerptu. Tělo filtru je zde definováno jako anonymní funkce (funkce bez jména) s parametrem $length. Tento parametr představuje původní délku výňatku, která je nastavena ve WordPressu. V těle anonymní funkce se nachází jednoduchý příkaz return 40;. Tento příkaz říká, že chceme, aby se úryvek textu zobrazil s délkou 40 slov. Toto číslo můžete libovolně změnit na jakoukoliv jinou hodnotu, podle vašich potřeb.

Poslední číslo 500 je priorita filtru. Vyšší číslo znamená vyšší prioritu. V tomto případě je použito číslo 500, což znamená, že tento filtr bude spuštěn později v procesu načítání obsahu, když se nastavuje délka excerptu. Když použijete tento snippet, délka úryvku se na Vašem blogu změní na požadovanou hodnotu (v tomto případě 40 slov). To ovlivní, kolik textu zobrazíte v seznamu článků nebo na dalších stránkách, které používají úryvky. Číslo 40 ve snippetu tedy buď snižte, nebo navyšte podle osobních preferencí.

More content about WordPress

Whole category is here

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