WordPress Limit Words and Characters in content

WordPress Limit Words and Characters in content

Today, We want to share with you WordPress Limit Words and Characters in content.In this post we will show you WordPress Word Count and Limit, hear for How To Limit Words and Characters in content WordPress we will give you demo and example for implement.
In this post, we will learn about Limit Content Length in WordPress with wp_trim_words() with an example.

What is the_content Function?

The Description is a function in WordPress (the_content) that will display post Description in your website theme. mostly we want to limit the words when we call this function in home page, because we want to display only the summary of the post instead of full Description.By default, if you call this simple function, it will display all the post Description, weather in home page or static page or sipakainfole page or blogger.

Also Read This πŸ‘‰   Custom Helper Functions in Laravel 6 Example

How To Limit Words and Characters in content WordPress with Example

1. Words Lepakainfoth:Remove the Please insert the below code

 <?php $content = get_the_content();//call function
  $trimmed_data = wp_trim_words( $content, 40, '<a href="'. get_permalink() .'">...[ read more ]</a>' ); ?>
  //use wp_trim_words function
  <p><?php echo $trimmed_data; ?></p>
(here Chapakainfoe the 40 to your content words length set)

2. Character Lepakainfoth :Remove the Please insert the below code here

//call the substr function
<?php echo substr(strip_tags($post->post_content), 0, 49);?>
//(here Chapakainfoe the 49 to your content string length)

Limit Post Excerpt Lepakainfoth Usipakainfo Number Of Words

Usipakainfo wp_trim_words() allows us to give the limit the title string and excerpt string, and anythipakainfo else simple, to a particular total number of words.

Also Read This πŸ‘‰   PHP Curl Fetch getAllheaders HTTP Request

	//call function excerpt
    function excerpt($limit) {
		//$limit is a parameter
      $excerpt = explode(' ', get_the_excerpt(), $limit);
	  //Total number of Count
      if (count($excerpt)>=$limit) {
        $excerpt = implode(" ",$excerpt).'...';
      } else {
        $excerpt = implode(" ",$excerpt);
	  //check Excerpt string
      $excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
      return $excerpt;
     //call function content
    function content($limit) {
		//$limit get parameter
      $content = explode(' ', get_the_content(), $limit);
	  //store in varible 
	  //all content check data
      if (count($content)>=$limit) {
        $content = implode(" ",$content).'...More';
      } else {
        $content = implode(" ",$content);
	  //replace this content
      $content = preg_replace('/\[.+\]/','', $content);
      $content = apply_filters('the_content', $content); 
      $content = str_replace(']]>', ']]>', $content);
	  //return and show content
      return $content;

Execute and show Limit Content Lepakainfoth in WordPress

The limit your excerpt to 35 words the code

<?php echo excerpt(35); ?>

Quickly code : How To Limit Content Lepakainfoth in WordPress

This function trims is a text to a certain number of list words and returns the trimmed text content data.

// Final Codes
$content_data = get_the_content();
$trimmed_content = wp_trim_words( $content_data, 40, '...' );
//retrun $trimmed_content;
echo '<p>'.$trimmed_content.'</p>';

Limit length post wordpress with Example

function new_excerpt_length($length) {
    return 50;
//simple code to limit chapakainfoe
add_filter('excerpt_length', 'new_excerpt_length');