Adding an automatic hyperlink to images

I created a blog for Wordpress for images. By posting all the posts, I did not use the wordpress editor to upload images. Instead, I used FillaZilla to upload images. Then, in the wordpress editor, I manually wrote only the image tag (below) in all posts and posted it. All messages do not contain text, but only images. Like this,

<img alt="" title="" src=""></img>

Now what I want to ask is that I want the images in all messages to receive automatic hyperlinks, the same as the src image. I have over 200 Wordpress blog posts. I do not want to edit them all one at a time. Here's the encoding of the wordpress content area,

<div class="post-entry">
                                            <p><img src='http://www.mywebsite.com/wp-content/uploads/2012/04/sun.jpg' title="sun" alt="sun" /></p>

</div>

Can someone help me with this? How can I add a hyperlink to images? Is there any code that I can put in a div after writing wordpress themes on my page?

@ chandu-vkm explained (in the comments) exactly what I was looking for. Now I have one more question. When I add a span tag in front of img, the @ chandu-vkm code mentioned does not allow adding a span tag immediately before the img tag. Instead, it places the place tag outside the p tag, as in the code below.

<div class="post_div">
<span class="entry"></span>
<p>
<img src='http://www.mywebsite.com/wp-content/uploads/2012/04/sun.jpg' title="Cute Teddy Bear" alt="Cute Teddy Bear" />
</p>
</div>

But I want the range to be placed immediately after p, like this.

 <div class="post_div">
        <p>
         <span class="entry"></span>
        <img src='http://www.mywebsite.com/wp-content/uploads/2012/04/sun.jpg' title="Cute Teddy Bear" alt="Cute Teddy Bear" />
        </p>
    </div>

Someone please help me.

+3
source share
2 answers

you can do it with some jquery

<div class="post_div">
    <img src='http://www.mywebsite.com/wp-content/uploads/2012/04/sun.jpg' title="sun" alt="sun" />
</div>

like this

$('.post_div img').each(function(){
$(this).wrap(function() {
  return '<a href="' + $(this).attr('src') + '" />';
})   
});

here is a sample http://jsfiddle.net/a4PYd/

+2
source

, <img>, functions.php:

function hyperlink_all_my_content( $content ) {
    $link = "http://www.somelink.com";
    return "<a href='$link'>$content</a>";
}
add_filter( 'the_content', 'hyperlink_all_my_content' );

, , wordpress.

EDIT:

function hyperlink_all_my_content( $content ) {

    $matches = array();
    $nummatches = preg_match("/src=['|\"](.*)['|\"]/", $content, $matches);
    return "<a href='" . $matches[1] . "'>$content</a>";
}
add_filter( 'the_content', 'hyperlink_all_my_content' );
0

All Articles