Question

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. https://i.stack.imgur.com/3Kavc.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.

Was it helpful?

Solution

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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top