WordPress.org

Ready to get started?Download WordPress

Forums

the_content into variable? (4 posts)

  1. oliverbennett
    Member
    Posted 4 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

  2. oliverbennett
    Member
    Posted 4 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/

  3. funkboybilly
    Member
    Posted 4 years ago #

    This way is a little easier:

    $content = get_the_content();

  4. Mark / t31os
    Moderator
    Posted 4 years ago #

    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().

Topic Closed

This topic has been closed to new replies.

About this Topic