Adding the_excerpt in WP

How to add auto excerpts to a WP Theme:

For this example, I’m using the WP Bootstrap Starter theme (remember to create a Child theme, or you will lose any edits after you update). You need to locate content.php file, it should be under the template-parts folder:

Find the code:

the_content( __( 'Continue reading →', 'wp-bootstrap-starter' ) );

Approx. line 33.

Replace with:

the_excerpt();

Then in the functions.php file, add:

function custom_excerpt_length( $length ) {
return 55;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

You can replace ’55’ with whichever # you want.

Read more

Here is the code to update the Read More text:

function custom_excerpt_more( $more ) {
return '... <a href="'.get_the_permalink().'">Read More</a>';
}
add_filter( 'excerpt_more', 'custom_excerpt_more' );

WP >> Settings >> Reading >> “Summary”

read more settings wp
Isaac Adams-Hands

Full Stack Developer, Digital Marketer, and InfoSec enthusiast. He received his Bachelor’s Degree from the University of Western Sydney and his Business Diploma from Georgian College before joining various marketing positions in search portals, e-commerce, higher education, and addiction recovery services.

Follow @ twitter

Related posts

Remove unwanted script from WP Header

I’ve noticed that WordPress adds tons of unwanted script to the header. I totally get why, but for highly focused themes, I like to remove as much as I can. This decreases page load times, eliminates render-blocking resources, and optimizes the First Link Priority Rule. The Script Using the script below, add it to your… Read More

WP Child Themes

WordPress child themes are really simple to make, but I’ve noticed most tutorials are more complicated then they need to be. All you need are two files in a folder: style.css + functions.php Style.css Replace Template: twentyseventeen with the name of your parent theme (it will be the folder name): function.php If you notice the… Read More