Replace image with its alt text?

You should be able to use the the_content filter for this. Something like this…

add_filter( 'the_content', 'wpse418925_replace_images_with_alt' );
function wpse418925_replace_images_with_alt( $content ) {
    // If you need to *only* do this on one post, check that we're in that post.
    // $desired_post can be an ID, post title, slug, or an array of any of those.
    if ( is_single( $desired_post ) ) {
        $content = preg_replace( '/<img.*(alt="[^"]+")[^>]*>/', '(Image. $1)', $content );
    }
    return $content;
}

… might do what you’re looking for.

Notes

  • This code is untested. Try it out on a local installation or a test site first.
  • This code is meant as a starting point only. In particular, it’s likely you’ll have to tweak the regular expression to suit your situation.
  • preg_replace() can be a “heavy” function, ie, time-intensive. You might want to consider caching the post’s modified content to an option or to post_meta.

References

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)