WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm making a slider that is getting images from attachments in the post. I am trying to rewrite the url for the post so that if someone pastes the direct url to the attachment, it'll go the post instead of the attachment page. I've no idea how to do that.

This site has something like this. click a image on slider, copy the url and paste it and you'll see it.

Thanks a lot for helping.

EDIT: code for the slider:

    var clist_autoplay = false;
    var ctemp_autoplay = clist_autoplay;
    jQuery(document).ready(function($) {        
        var larr = {
$num = 1;
$images = array_values($images);
foreach ($images as $key => $attachment) {
    $image_img = wp_get_attachment_image_src( $attachment->ID, 'large' );
    $alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
    $image_title = $attachment->post_title;
    $caption = $attachment->post_excerpt;
    $description = $attachment->post_content;     
            "<?php echo $image_title ?>": {
                "0": "<?php echo  $image_img[0] ?>",
                "1": 600,
                "2": 400,
                "3": "<?php echo $image_title ?>",
                "4": "#",
                "5": "<?php echo $image_title ?>",
                "6": "",
                "7": "",
                "8": "",
                "9": "",
                "num": <?php  echo $num++; ?>,
                "slideTitle": "<?php echo $caption ?>",
                "slideContent": "<p><?php echo $description; ?></p>",
                "slideNum": null
                <?php if (isset($images[$key+1])) { ?>
                    , "next": "<?php echo $images[$key+1]->post_title; ?>"
                <?php } ?>
                <?php if (isset($images[$key-1])) { ?>
                    , "prev": "<?php echo $images[$key-1]->post_title; ?>"
                <?php } ?>
<?php } // end foreach ?>

I need to put the url in the 4th key so that the image attachemnt link also gets redirected to the post. my demo: http://goo.gl/OsMxe

share|improve this question
Please post the code for the slider. – s_ha_dum Dec 28 '12 at 18:03
I've added the code. thanks. – Samia Ruponti Dec 28 '12 at 18:11

You want the permalink for the attachment's parent post, so, if I am guessing correctly about the contents of $attachment

$parent_url = get_permalink($attachment->post_parent);

share|improve this answer
err..not quite. I want the attachment url to show, but to stay in the parent post. like this goo.gl/LUlQM . – Samia Ruponti Dec 28 '12 at 18:50
You are going to have to have both URLs. One for the image src and one for an anchor around the image that would link to the parent. This last one is what I told you how to get. If you want to be able to paste, for example <htpp://pigeonsandplanes.com/wp-content/uploads/2012/12/end-world1-600x400.jpg> and have the request return the parent page (which is not how your example page works. I can get the image itself without a problem) you are going to have to do something very different from what you are doing and your Javascript has nothing to do with it. – s_ha_dum Dec 28 '12 at 19:06
you dont understand my question, – Samia Ruponti Dec 28 '12 at 19:20
Then rewrite your question. – s_ha_dum Dec 28 '12 at 19:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.