Editing <?php the_content(‘Read more…’); ?>

Is it possible to automatically add for example image before first h2 tag in
the_content?

Related posts

1 comment

  1. 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);
      return $content;
    }
    
    add_filter( 'the_content', 'my_the_content_filter' );
    

Comments are closed.