• I am trying to display the URL of an Image after every image in the main content on WordPress. To do this I am building a plugin.

    If add the following code within my plugin I can display 2 of the same Image as the code to display the image is stored in $1 below.

    $content = preg_replace("/(<img([^>]*)>)/i",
        "<div class=\"image_wrap\">$1<div class=\"linkbox\">" .
        "$1</div></div>", $content );

    In theory all I need to do is hack at the second instance of $1 in the above code to strip the image src. So below is the code I have tried and it using some substr and strpos funtions but that doesn’t seem to want to work for me.

    $content = preg_replace("/(<img([^>]*)>)/i",
        "<div class=\"image_wrap\">$1<div class=\"linkbox\">" .
         substr(substr("$1", strpos("$1","src=\"")+5), 0,strpos(substr("$1",strpos("$1","src=\"")+5),"\"")) .
    </div></div>", $content );

    Is there anything glaringly wrong with this?

  • The topic ‘Displaying the SRC of and Image after the Image’ is closed to new replies.