Normally I wouldn't insert a single post with a technique like this, but sadly this project requires it.

I try to call the post_title with:

echo apply_filters( 'the_content', get_post_field( 'post_title', $post_id ) );

The problem is, that this code will display the title inside a paragraph like:


How can I block it out, or even replace it with an h2?

  • Why do you need this? Are you using shortcodes in titles?
    – birgire
    Commented May 27, 2016 at 12:57
  • Why the_content and not the_title ? the_content uses wpautop() which will add those paragraphs. But, You could use regex to replace p with h2
    – Ismail
    Commented May 27, 2016 at 12:58
  • 1
    @SamuelElh thank you, this is the solution. Single posts are confusing me. This was the solution.
    – marvinpoo
    Commented May 27, 2016 at 13:01

1 Answer 1


As per the discussion

the_content is not a proper hook for filtering post titles while it filters the post content. wpautop() function is called with the_content so it adds the necessary paragraphs.

To filter post titles use the_title instead, it won't add any markup tags by default:

echo apply_filters('the_title', get_post_field('post_title', $post_id));
  • No worries. Have a good day!
    – Ismail
    Commented May 27, 2016 at 13:10

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.