LATEST >>

Welcome Here And Thanks For Visiting. Like Us On Facebook...

EXEIdeas – Let's Your Mind Rock » WordPress / WordPress Tips » How To Pick Limited Characters From WordPress (the_excerpt) Snippet?

How To Pick Limited Characters From WordPress (the_excerpt) Snippet?

How-To-Pick-Limited-Characters-From-WordPress-the_excerpt-Snippet
If you ever used any premium WordPress theme then you have see limited characters of every post on your blog main page as then have already added it into there theme. But if you are designing your own WordPress theme from scratch then you will not get short post introduction in your blog main page.

So through the below codes, you can pick your desired no of characters from every post that you want to show at your blog main page. This will help you to save space on ypour blog main page and also you will be able to add more posts on front page that will look great. So now without any more preface, move forward to the code…

How To Pick WordPress Post Excerpt By Default?

Below are the codes to pick WordPress Post Excerpt by default and will contain default characters length.

<?php the_excerpt(); ?>

 

<?php
$my_excerpt = get_the_excerpt();
if ( $my_excerpt != '' ) {
	// Some string manipulation performed
}
echo $my_excerpt; // Outputs the processed value to the page
?>

How To Pick WordPress Post Excerpt Limited Chracters By Default?

Below are the codes to pick WordPress Post Excerpt by default and will contain limited characters length.

<?php echo substr(get_the_excerpt(), 0,300); ?>
<?php
the_excerpt_max_charlength(300);

function the_excerpt_max_charlength($charlength) {
	$excerpt = get_the_excerpt();
	$charlength++;

	if ( mb_strlen( $excerpt ) > $charlength ) {
		$subex = mb_substr( $excerpt, 0, $charlength - 5 );
		$exwords = explode( ' ', $subex );
		$excut = - ( mb_strlen( $exwords[ count( $exwords ) - 1 ] ) );
		if ( $excut < 0 ) {
			echo mb_substr( $subex, 0, $excut );
		} else {
			echo $subex;
		}
		echo '[...]';
	} else {
		echo $excerpt;
	}
}
?>

Customization:

Just replace 300 with your desired characters count that you want to pick out of all excerpt text. Rest all is default.

Recommended For You:
Using Google Trends For SEO: The 5 Best Ways To Follow

Last Words:

This is what we have and shared in easy steps for newbies so that they can easily know how it works. Stay with us because we are going to share a whole guide step by step about WordPress and make it easy for you. If you liked it then share it and be with us to get next tutorial. If you have any problem then feel free to ask us. We will help you with what we can or have.

You Like It, Please Share This Recipe With Your Friends Using...

Be the first to write a comment.

Leave a Reply

Your email address will not be published. Required fields are marked *