WordPress.org

Make WordPress Core

Opened 2 years ago

Last modified 2 years ago

#22101 new defect (bug)

Gallery shortcode with link="file" is not linking the file in the RSS feed

Reported by: ifrins Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.4.2
Component: Feeds Keywords:
Focuses: Cc:

Description

Hi,
In a WordPress site I'm currently developing I want to use the stock gallery shortcode. I use [gallery link="file"] to link directly the image URL which, should fix Flipboard, Currents et al. showing just a little thumbnail.

In the page the code is displayed properly and the a tag links the image file, but, on the RSS feed, it links to the attachment page.

I've tested this in the latest nightly version 3.5-beta1-22104 and on the stable 3.4.2. I attach the output of the page and the feed.

Attachments (2)

page-output.html (2.7 KB) - added by ifrins 2 years ago.
Page HTML Output
feed-output.xml (2.0 KB) - added by ifrins 2 years ago.
Feed Output

Download all attachments as: .zip

Change History (6)

@ifrins2 years ago

Page HTML Output

@ifrins2 years ago

Feed Output

comment:1 @ifrins2 years ago

  • Cc francesc.bgr+ifrins@… added

comment:2 follow-up: @mdgl2 years ago

This happens because for some reason the gallery shortcode deliberately generates completely different output for feeds. In file wp-includes/media.php the function gallery_shortcode() contains the following lines:

if ( is_feed() ) {
        $output = "\n";
        foreach ( $attachments as $att_id => $attachment )
                $output .= wp_get_attachment_link($att_id, $size, true) . "\n";
        return $output;
}

Why it would want to do this is anybody's guess! Maybe it's just a hangover from the days of the limited functionality of early feed readers. In any case, as I hope you can see, the code doesn't reference the gallery link option at all.

There appear to be two options to fix the problem. Firstly, we could just delete the block of code above and allow feed output to contain the full gallery HTML/CSS as though it was a normal page. Alternatively, we could modify the code above to respect the value of the gallery link option, something like the following (note this has not been tested - it's just a suggestion, but based on similar code that occurs later on in the gallery shortcode function):

if ( is_feed() ) {
        $output = "\n";
        $permalink = !isset($attr['link']) || 'file' != $attr['link'];
        foreach ( $attachments as $att_id => $attachment )
                $output .= wp_get_attachment_link($att_id, $size, $permalink) . "\n";
        return $output;
}

What do you think? What should be the correct behaviour of the gallery within feeds?

comment:3 in reply to: ↑ 2 ; follow-up: @SergeyBiryukov2 years ago

Replying to mdgl:

Why it would want to do this is anybody's guess!

Introduced in [7298] (for #6225).

comment:4 in reply to: ↑ 3 @mdgl2 years ago

Replying to SergeyBiryukov:

Introduced in [7298] (for #6225).

Ah yes, the world was a different place in 2008!! Including perhaps the ability to get away with a one-line bug report containing no example or explanation :-)

Note: See TracTickets for help on using tickets.