• I’m using a plug-in to hide spoilers on my blog; it’s quite simple, as it just wraps the spoiler in a div, and then toggles that div’s visibility. Because of this, though, the spoiler will be visible in the RSS feeds.

    What I’d like to do is modify the content of the posts before they’re added to the feed. I’ve done a fair bit of reading, and it seems it should be possible … but I’m not a programmer by trade, so I’m muddling a bit and could use some help. (I do know my way around the WP code base, and have written a couple simple shortcode plugins, plus some PHP scripts, so I’m not totally in the dark.)

    I think I need to create a custom feed (or many, one for each feed type?), and massage the content before it’s added to the feed. I think I can do what I need with a fairly straightforward preg_replace, as the spoiler sections are clearly marked with this HTML…

    <div class="spoiler-wrap"><div class="spoiler-head no-icon collapsed" title="Expand">Spoiler</div><div class="spoiler-body" style="display: none;">This is the spoiler text I'd like to remove</div><noscript><div class="spoiler-body">

    I can find that bit easily with a regex, and use preg_replace to insert something like “Spoiler hidden—view on the site to reveal.” But that’s as far as I’ve gotten; my questions are…

    1) Is this actually possible?
    2) If it is possible, what do I need to do?
    3) A post can have multiple spoiler tags, so I’d need to catch all of them, so I think some sort of loop around the preg_replace would be needed.

    Thanks in advance for any help!

    -rob.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You don’t need to create a custom feed.
    If your spoiler plugin is a shortcode, it might be a different answer than if it isn’t.

    For shortcode: write a filter for the_content_feed with a low number priority (runs early) that replaces the shortcode with your generic spoiler message.

    For no shortcode: write a filter for the_content_feed that replaces the whole spoiler div with your generic spoiler message.

    Thread Starter griffman

    (@griffman)

    Great, thanks for the pointer—I’ll see if I can get that working.

    -rob.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Modify post content in RSS feed?’ is closed to new replies.