We can use the post_gallery
filter to modify/replace the default WordPress gallery template (AKA output code) to suit our needs. But this doesn’t seem to affect the markup in RSS feeds.
No matter what I do, the markup for gallery images in my RSS feed is simply like this:
<a href="#1">
<img src="#2" />
</a>
<a href="#3">
<img src="#4" />
</a>
So, is there a way (something like a filter, function, etc.) to modify the default WordPress gallery markup in RSS feeds?
What I’ve tried
For a start (just to check), all I had to do was comment out this bit in wp-includes/media.php
core file:
if ( is_feed() ) {
$output = "\n";
foreach ( $attachments as $att_id => $attachment )
$output .= wp_get_attachment_link($att_id, $size, true) . "\n";
return $output;
}
And it kinda worked. Now the gallery markup in my RSS feeds is the same as what you see on the front-end of my site (i.e. in posts).
But when I do the same using the post_gallery
filter, it doesn’t work—the markup in RSS feeds is unaffected. I have no idea why!
On the whole, this is the code (related to post_gallery
) in my functions.php. Am I doing something wrong?
Since I am frequently asked what I am trying to do—in this case, I want to modify the markup for WordPress galleries in RSS feeds to look like this:
<section class="fl-slideshow">
<figure>
<img src="#2" width="1200" height="900">
<figcaption>Puppies are cute</figcaption>
</figure>
<figure>
<img src="#4" width="900" height="1200">
<figcaption>Kittens are too</figcaption>
</figure>
</section>