Substitute of the_excerpt() function: Show blog post upto Read More in Home Page keeping all html formatting intact .

Today i will share you a new thing which i have learned recently… This problem,which i guess, is faced by most of the bloggeer who wants to show some limited contents or texts in the homepage by maintaining the html formatting of the posts.

What we generally do, we use the_excerpt() function instead of the_content() function to show some limited text in the homepage.

But, you have noticed that if you use the_excerpt() function, the html formatting for example Line break

 "<br>","<p>" 

and the other html formatting doesn’t work.
 

So, if you want to show the limited content (upto “Read more”) of your post in the homepage keeping all the html formatting intact you have to do the following steps..

Please do comments if you have faced any problem implementing this.
 

Here are the 2 easy steps to follow
 

 

1. Go to your function.php (from Appearance–>Editor) and paste the following code.

function get_the_content_with_formatting ($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
	$content = get_the_content($more_link_text, $stripteaser, $more_file);
	$content = apply_filters('the_content', $content);
	$content = str_replace(']]&gt;', ']]&gt;', $content);
	return $content;
}

See the image.


2. Go to index.php or content.php or loop.php ( you need to check which theme/php file is using by your theme) and replace the_content() or the_excerpt() function with the following one.
get_the_content_with_formatting() function. See the image below.

3. You are done. :)

If this Article seems helpful to you? You can Let me buy a coffee :)

 

Please make some donations

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 293 other followers

%d bloggers like this: