Title: the_content into variable?
Last modified: August 19, 2016

---

# the_content into variable?

 *  [oliverbennett](https://wordpress.org/support/users/oliverbennett/)
 * (@oliverbennett)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/the_content-into-variable/)
 * 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

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [oliverbennett](https://wordpress.org/support/users/oliverbennett/)
 * (@oliverbennett)
 * [16 years, 6 months ago](https://wordpress.org/support/topic/the_content-into-variable/#post-1280304)
 * 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/](http://digwp.com/2009/07/putting-the_content-into-a-php-variable/)
 *  [funkboybilly](https://wordpress.org/support/users/funkboybilly/)
 * (@funkboybilly)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/the_content-into-variable/#post-1280690)
 * This way is a little easier:
 * `$content = get_the_content();`
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/the_content-into-variable/#post-1280691)
 * [http://codex.wordpress.org/Template_Tags/the_content](http://codex.wordpress.org/Template_Tags/the_content)
   
   [http://codex.wordpress.org/Function_Reference/get_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()`.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘the_content into variable?’ is closed to new replies.

## Tags

 * [the_content](https://wordpress.org/support/topic-tag/the_content/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 3 participants
 * Last reply from: [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * Last activity: [16 years, 4 months ago](https://wordpress.org/support/topic/the_content-into-variable/#post-1280691)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
