Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - How do I get `<?php the_content(); ?>` as a string or turn it into a string

Tags:

php

wordpress

I use a lot the function:

get_search_query() 

To get the value returned from searches and to be able to modify and use the string.

I need to know a function to get <?php the_content(); ?> as a string or how to turn what that function returns into a string.

The content is just a simple word with paragraph tags but using that function I also get the tags, I want to get just the text so I can add it to a hyperlink.

like image 963
lisovaccaro Avatar asked Dec 10 '10 03:12

lisovaccaro


3 Answers

I think you're looking for get_the_content(), which is well documented: http://codex.wordpress.org/Function_Reference/the_content

like image 83
deceze Avatar answered Nov 13 '22 06:11

deceze


If you need to store it in a variable with html formatting do this

apply_filters('the_content',$post->post_content)
like image 31
Mark Avatar answered Nov 13 '22 07:11

Mark


Don't know WP, but the implied naming convention would suggest get_the_content(). Additional googling reveals a variation get_the_content_with_formatting

An alternative would be however to wrap the_content() into ob_start() and ob_get_contents()+ob_end(). The latter returns any print output made until then.

like image 2
mario Avatar answered Nov 13 '22 08:11

mario