If you do not provide an explicit excerpt to a post. HTML tags and graphics are stripped from the excerpt's content. How to use the_excerpt in Wordpress

How to use the_excerpt in WordPress

We all know what is excerpt. In wordpress using excerpt is good idea. WordPress provides the inbuild function called the_excerpt. Many people want to to show first few words on the theme front page. For that this function is very useful.

How to use the_excerpt in WordPress

How to use the_excerpt in WordPress
How to use the_excerpt in WordPress

If you do not provide an explicit excerpt to a post (in the post editor’s optional excerpt field), it will display an automatic excerpt which refers to the first 55 words of the post’s content. Also in the latter case, HTML tags and graphics are stripped from the excerpt’s content.

Important Note: the_excerpt function must be written in The Loop.
For using the excerpt tag you need to put following code in the loop.

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1">php</span> the_excerpt(); ?-->

Some times you need to put excerpt tag conditionally. In archive or category and home page you want to show only the excerpt of post then you can use following code:

<!--?<span class="hiddenSpellError" pre="" data-mce-bogus="1">php</span> if ( is_category() || is_archive() || is_home() ) {-->
	the_excerpt();
} else {
	the_content();
} ?-->

If you want to Control Excerpt Length using Filters use following code. To change excerpt length using excerpt_length filter, add the following code to functions.php file in your theme:

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

use the_excerpt in WordPress

Tip: You can Remove […] string using Filters.By default, excerpt more string at the end is set to ‘[…]’. To change excerpt more string using excerpt_more filter, add the following code to functions.php file in your theme:

function new_excerpt_more($more) {
	return '[.....]';
}
add_filter('excerpt_more', 'new_excerpt_more');

If you want to make read more link after excerpt then use following code:

function new_excerpt_more($more) {
       global $post;
	return '<a href="'. get_permalink($post->ID) . '">' . 'Read the Rest...' . '</a>';
}
add_filter('excerpt_more', 'new_excerpt_more');

Published by

Purab

I am Purab from India, Software development is my profession and teaching is my passion. Programmers blog dedicated to the JAVA, Python, PHP, DevOps and Opensource Frameworks. Purab's Github Repo Youtube Chanel Video Tutorials Connect to on LinkedIn

Leave a Reply

Your email address will not be published.