Grow your CSS skills. Land your dream job.

How to add a DIV to this JS code

  • # October 12, 2012 at 11:03 am

    I have a comment embedder plugin that allow my users to upload a photo with their comments. Now I want to give that photo, a special DIV. Here is its main code:

    function embed_images($content) {
    $content = preg_replace(‘/[img=?]*(.*?)([/img)?]/e’, ‘”“‘, $content);
    return $content;
    }

    Where to add the DIV?
    *the image add with a[img][/img] shortcode to the comment.

    # October 12, 2012 at 11:11 am

    There’s a few easy ways to handle this. You could wrap your $content with a string “

    ” + preg…. + “

    “; Or more simply add another line after $content.

    function embed_images($content) {
    $content = preg_replace(‘/[img=?]*(.*?)([/img)?]/e’, ‘”“‘, $content);
    $content = “

    ” + $content + “

    “;
    return $content;
    }

    The second options would be simpler to read. Also this is just a php way of doing it, If you wanted to you could have a js library handle the images and wrap them as well.

    # October 12, 2012 at 11:13 am

    Oh wow markdown stipped the first examle.

    $content = “

    ” + preg_replace(‘/[img=?]*(.*?)([/img)?]/e’, ‘”“‘, $content) + “

    ;

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".