How To Get Formatted Content By get_the_content() Function In WordPress

Hi Friends, Today I am going to write about how can we get formatted content by get_the_content wordpress function. get_the_content function can be used in loop and by this function we can get content in one variable and can be print it later. But when we use this function the content it returns is not formatted. So many times it happens that we need to use this function and also want formatted content. So below i am going to explain that how can we get formatted content via get_the_content function.

So to get formatted content via get_the_content() function , first open your functions.php file exists in your theme folder, then paste below code anywhere in your functions.php file.

function get_the_content_formatted ($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(']]>', ']]>', $content);
return $content;
}

Ok, So now in above function we use get_the_content function in first line and in second line we use wordpress filter which is using the_content on $content variable , So we will get formatted content by this function. So after putting this in functions.php, Wherever you want to use formatted content then use get_the_content_formatted() function like this :

echo get_the_content_formatted(); 

I hope this post helpful for someone. If you have any question then you can ask me anytime or post it in comment.

Also I am WordPress Developer, Freelance PHP Developer having more than 3 years of experience, So if you want to do any projects then you can contact me.

Hostgator Hosting in 1 Cent Coupon Code – “1CENTHECOUPON” (Without Quotes).