Trim additional tags from image URL

I want the URLs of the images to be automatically added at the time of publication in the post / comment field in the Wordpress theme.

This code already works for me in functions.php:

function content_magic($content) { $content = get_the_content(); $m= preg_match_all('!http://[a-z0-9\-\.\/]+\.(?:jpe?g|png|gif)!Ui' , $content , $matches); if ($m) { $links=$matches[0]; for ($j=0;$j<$m;$j++) { $content=str_replace($links[$j],'<img src="'.$links[$j].'">',$content); } } return $content; } add_filter('the_content','content_magic'); 

BUT: as soon as you send iphone via the Wordpress application, it no longer works, because messages with images from the iphone application automatically add tags alt = "20121108-172156.jpg" class = "alignnone size- full" / "> at the end after "

how can I truncate the "alt" and "class" tags after the end of the url starting with ?: jpe? g | png | gif "before" / "> with the code above?

+4
source share

Source: https://habr.com/ru/post/1445018/


All Articles