Tutorials WordPress Limit Archive Page Content with Read More Link in WordPress

Limit Archive Page Content with Read More Link in WordPress

Most of the classic WordPress blog themes display full content in archive page. If you want to limit the archive post content with a read more button, then add the following snippet to your theme function.php file.

Example:
Limit Archive Page Content and Add Read More Link in WordPress

add_filter("the_content", "break_text");
function break_text($text){
  if(is_front_page() || is_archive() || is_search())
  {
    $length = 400; // limited to 400 characters
    if(strlen($text)<$length+10) return $text; //don't cut if too short
    $break_pos = strpos($text, ' ', $length); //find next space after desired length
    $visible = substr($text, 0, $break_pos);
	$read_more = "... <br><center><a href='".get_permalink()."' class='wp-btn'>Read more..</a></center>";
    return balanceTags($visible) . $read_more;
  } else {
    return $text;
  }
}
Total
0
Shares
guest
0 Comments
Inline Feedbacks
View all comments
Previous Post
Wordpress Tutorials

How to List All the Categories for Custom Post Type

Next Post

Get Domain Name from URL in PHP Using Regular Expressions

Related Posts
By clicking “Allow All”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookie Notice
Allow All
0
Would love your thoughts, please comment.x
()
x