How to assign the value of the result variable to the_content () without outputting it to the page.

get_the_content () does not fit, because although it assigns the content to a variable, all html tags disappear there, everything floats and does not have the same form as when calling the_content ().

Is there such a solution ???

$ var = the_content (); // the value of the post should not appear on the site

    1 answer 1

    You can use php buffering.

    ob_start(); the_content(); $content = ob_get_clean(); 

    And you can get by with WordPress features.

     $content = get_the_content(); $content = apply_filters( 'the_content', $content ); $content = str_replace( ']]>', ']]>', $content ); 

    Just get_the_content() does not work, because filters must be applied to it.

    • Thanks, helped !!! - Victor Vasilyev