get_content() WITH formatting

2010-01-16 @ 14:55

The problem

Normally the get_the_content() tag returns the content WITHOUT formatting. Only the_content() will print the content WITH formatting.

<?php echo get_the_content(); ?>
<?php the_content(); ?>

The solution

I found out a solution in WordPress core to make get_the_content() tag return the same content as the_content(). Put this code into your functions.php in your theme folder.

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

The function call

Call the function inside the loop somewhere in your theme.

<?php echo get_content(); ?>

Improvements

Do you have any ideas, bugs, features or anything else to improve the code? Write a comment and I’ll look into it

RSS-feed for comments

4 replys to “get_content() WITH formatting”

  • GF Prints »
    2010-01-10 @ 2:49 e m

    Thanks for this solution, was having troubles with some php scripts there,.

    cheers

    Reply
  • illis
    2010-02-11 @ 7:50 f m

    This is excellent, thank you very much!

    Reply
  • riiii
    2010-10-31 @ 10:16 f m

    hi, do you also know how to output the content without using wordpress functions directly out of the database eg using echo?

    Reply
  • smotru »
    2011-04-02 @ 7:00 e m

    Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 16387 bytes) in

    Reply

Leave a reply