oliverbennett
Member
Posted 2 years ago #
Here there,
I want to put contents of the_content() into a variable, as I'm then using it for other stuff, but if I do something like this in my loop:
<?php
$foo = the_content();
?>
It just prints the_content() out like normal... is there any way of getting it inside $foo and not printed out?
Many thanks,
Oliver
oliverbennett
Member
Posted 2 years ago #
My Google-Fu must be weak. On a second search I found the answer:
ob_start();
the_content();
$content = ob_get_clean();
http://digwp.com/2009/07/putting-the_content-into-a-php-variable/
funkboybilly
Member
Posted 2 years ago #
This way is a little easier:
$content = get_the_content();
http://codex.wordpress.org/Template_Tags/the_content
http://codex.wordpress.org/Function_Reference/get_the_content
the_content(); // Echoes the value
get_the_content(); // Returns the value
Like fbb said above, use get_the_content().