WordPress.org

Ready to get started?Download WordPress

Forums

P2
Auto embed image urls in posts/comments (1 post)

  1. tomhaegler
    Member
    Posted 1 year ago #

    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 "/> ?

Topic Closed

This topic has been closed to new replies.

About this Theme

About this Topic

Tags

No tags yet.