I'm using Wordpress' CMS for my website, I want to display recent blog posts, but without the HTML tags which are within the post. I have tried the following, but to no avail.
$content = the_content();
$content = strval($content);
echo strip_tags($content, '<p><a>');
Which returns the following error:
Parse error: syntax error, unexpected 'the_content' (T_STRING) in C:\xampp\htdocs\wp\wp-content\themes\My-theme\index.php on line 25
the_content()
will directly echo your content so you are getting the error. Try
$content = get_the_content(); //returns the content so your $content will have all the contents
$content = strval($content);
echo strip_tags($content, '<p><a>');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.