Turning a submitted image from frontend into a link to its own source

This is a wordpress related question. I want to turn an image that was submitted via frontend submission form where you provide the external url into an image that links to its own source. For ex. http://i.imgur.com/7qmFBPa.jpg would be the end result of clicking on the image link. Heres what the php looks like at the moment:

<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
    <?php if ( has_post_thumbnail() ) { ?>
        <div class = 'span4 reddit-image-single pull-left'>
            <img src = "<?php echo $image[0]; ?>" width = "700px" class="img-rounded">
        </div>
    <?php }else{ ?>
        <div class = 'span4 reddit-image-single pull-left'>
            <img src = "<?php echo get_post_meta( $post->ID, 'wpedditimage', true ); ?>" width = "700px" class="img-rounded">
        </div>
<?php } ?>

how do i go about modifying the above code? I'm fairly new to PHP.

Solutions

wrap the image in tags with the url as the href

<?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
    <?php if ( has_post_thumbnail() ) { ?>
        <div class = 'span4 reddit-image-single pull-left'>
            <a href="<?php echo $image[0];?>"><img src = "<?php echo $image[0]; ?>" width = "700px" class="img-rounded"></a>
        </div>
    <?php }else{ ?>
        <div class = 'span4 reddit-image-single pull-left'>
            <a href="<?php echo get_post_meta( $post->ID, 'wpedditimage', true ); ?>"><img src = "<?php echo get_post_meta( $post->ID, 'wpedditimage', true ); ?>" width = "700px" class="img-rounded"></a>
        </div>
<?php } ?>

This is the main line you want to look at

<a href="<?php echo $image[0];?>"><img src = "<?php echo $image[0]; ?>" width = "700px" class="img-rounded"></a>
Tags: PHP / Wordpress

Similar questions

Turning variable into a value set in shortcode
I have a site on WordPress, and first of all I have this PHP shortcode that helps me to make customizable links in WP post editor without turning my CSS files into a dump of classes with basically the same parameters. It lets me to put custom $url, background color of the button $color and icon $icon. It supposed to turn out like this, for example:...
MySQL - Joining tables and turning specific rows into "virtual" columns
I am doing some database queries on Wordpress. I am joining the usermeta table and users table. the users table has a single row for each user. the usermeta table has multiple rows for each user as the "meta_keys" (categories of meta data of each user) can contain all kind of information. In a query I now would like to create a result set with only...
Turning a Wordpress post_meta table into an easier to use View
I'm using Wordpress and trying to create a view to make reviewing and analyzing my resort data a little easier. Resort data is stored in the post_meta table in Wordpress and referenced in a custom post type known as "resorts". The following query gives me the result set I want to parse: What I want to do with this result set is have each unique met...
Is turning input and label into block level items okey?
I know that you can't (semantically) do something like: I am working on the comment_form() for WordPress: I am using Foundation's mixin's (sass) to set a grid to label and input. This mixin will make the label and input a block (those are normally a inline). Is this, okey? Should I put the label and input in 2 different div's again and set the grid...
Turning SQL Distinct data into readable list in php
I have some custom tables in Wordpress that store information about people, linked to a post, and I want to be able to generate a summary of the data, specifically, a sentence along the lines of: I currently pull out the data as follows: Which returns an array of objects as follows: So at the moment, I just do this: which returns: Clearly not accep...
Turning my current website configuration into a wordpress theme
My searches for this keep turning up "How to make a wp theme from scratch" which is not what I want. I made a website using the theme Scrawl, but I made a bunch of modifications. I would like to turn this into a theme so I can use it to make other sites without having to do much of the work again. Is it possible?

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.