title: Replacing alt and title with filter for each image in post (WordPress)
body: <p>I have updated hundreds of images in WordPress with the proper alt and title information in the media library and now I need to get the page to render the correct information without having to update each page individually. </p>
  
  <p>It seems like using <code>add_filter</code> or something similar will do what I need, but I'm not sure whether I need to figure out a regular expression or if I can just use <code>the_content</code>. </p>
  
  <p>I have put together a way to get all attached images and display the correct alt and title tags, but I only know how to add the images to the beginning or end of <code>the_content</code>. I need it to replace each corresponding image that is already there. Is there a better way to do this? Here is a function to put the new image content into an array:</p>
  
  <pre><code>function replaceimages_get_images($content) {
      global $post;
      $images = array();
      $x = 0;
      $args = array(
          'post_type'   =&gt; 'attachment',
          'numberposts' =&gt; -1,
          'post_status' =&gt; null,
          'post_parent' =&gt; $post-&gt;ID,
          'exclude'     =&gt; get_post_thumbnail_id()
      );
  
      $attachments = get_posts( $args );
      if ( $attachments ) {
          foreach ( $attachments as $attachment ) {
              $src = wp_get_attachment_image_src( $attachment-&gt;ID, 'full' );
              $title = apply_filters( 'the_title', $attachment-&gt;post_title );
              $alt = apply_filters( 'alt', get_post_meta($attachment-&gt;ID, '_wp_attachment_image_alt', true ));
              $images[$x] = '&lt;img src="'.$src[0].'" title="'.$title.'" alt="'.$alt.'" /&gt;';
              $x++;
          }
      }
      return $content;
  }
  add_filter( 'the_content', 'replaceimages_get_images' );
  </code></pre>
  
  <p>I need to now, in pseudocode, do the following:</p>
  
  <pre><code>for each image in $content {
      match src to image in array;
      replace entire image with image from array;
  }
  </code></pre>