WordPress.org

Support

Support » Themes and Templates » P2 » Auto embed image urls in posts/comments

Auto embed image urls in posts/comments

  • tomhaegler

    @tomhaegler

    I got this to work with this code 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 post via wordpress iphone app – it doesn’t work anymore because image posts from the iphone app end with “<img src=”http://image.jpg” alt=”20121108-172156.jpg” class=”alignnone size-full” />

    how can I cut off from .jpg” to “/> ?

  • The topic ‘Auto embed image urls in posts/comments’ is closed to new replies.
Skip to toolbar