0

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

1 Answer 1

2

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>');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.