How to Hack Formatted Content In WordPress

>> Thursday, August 04, 2011

Today I am going to write about how can we get formatted content by get_the_content wordpress function. This 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 is how can we get formatted content via get_the_content function.

First open your functions.php file exists in your theme folder and 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;

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 as given :

echo get_the_content_formatted(); 

I hope this will helpful to you. Please let me know if you have any question.

blog comments powered by Disqus

Post a Comment

Related Posts with Thumbnails

  © Blogger template Webnolia by 2009

Back to TOP