How to update an image attachment’s alt text from a custom field when saving a post?

I found the problem. It was updating the post instead of the attachment. So instead of $post->ID, I create another string that stores the image ID and replace that with post->ID and it works. function post_extra_save( $post_id, $post){ if ( has_blocks( $post->post_content ) ) { $blocks = parse_blocks( $post->post_content ); foreach ( $blocks as $block … Read more

How to generate alt attributes with php / filters?

Maybe not the best solution, but did it like this: function add_alt_tags($content) { global $post; $content = str_replace(‘alt=””‘, ‘alt=”‘.$post->post_title .'”‘, $content); return $content; } add_filter(‘the_content’, ‘add_alt_tags’, 100);