Search code examples
wordpressposts

Give Out Wordpress post_content?


My problem is that I want give out post_content, but the output is with raw shortcodes and HTML.

I need an output with the correct translating.

A link should be a link and not a href, but only normal text with links.

When a media file is inside the post, I want to ignore this.

I don't want a big preview for my posts - only a simple one.

My output code:

$html .= '<p>'.string_limit_words($numpost->post_content, 20).'</p>';

Solution

  • You need to pass $numpost->post_content through the the_content filter, like so:

    apply_filters( 'the_content', $numpost->post_content )

    Further reading: https://developer.wordpress.org/reference/hooks/the_content/