Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is there possible to automatically add for example image before first h2 in the_content ? Thank you

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Yes, it is possible.

You can use the_content hook and assign your own filter to this hook.

Then you should (that is the part when things get a little bit messy) parse and replace content of that post.

So for example you can do it like so:

function my_the_content_filter($content) {
  $content = str_replace('<h2 ', '<img src=""...><h2 ', $content, 1);
  return $content;

add_filter( 'the_content', 'my_the_content_filter' );
share|improve this answer
It says error :( Fatal error: Cannot pass parameter 4 by reference in – Chymmi Jul 4 '13 at 14:12
in...? The rest of this message is important. – Krzysiek Dróżdż Jul 4 '13 at 14:39

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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