Changing output markup of an media file

I am creating a wordpress theme for a friend and am trying to add some markup before and after an image that has been inserted using the media button on a post.

Here is what I have so far but it’s giving me an error. Any suggestions or help would be much appreciated!

add_filter ('the_content', 'wpse264886_content_insert_html', 10, 1);
function wpse264886_content_insert_html ($content) {
  $html1 = 'before ... ';
  $html2    =  'after ...';
  $content = preg_replace('/(<a.*?)><(img.*?)/', '$1>' . $html1 . '<$2>' . $html2, $content);
  return $content;
  }

Thanks!

Ponte

Read more here: Changing output markup of an media file

Leave a Reply

Your email address will not be published. Required fields are marked *