WordPress.org

Ready to get started?Download WordPress

Forums

Exclude DIV from RSS (10 posts)

  1. ptvguy
    Member
    Posted 7 years ago #

    Is there a way to exclude a certain DIV class from going out with the RSS feed? I'm including a kind of magazine-style pullout quote in my posts that basically repeats some piece (or pieces) of the post content to make them stand out on the side. The problem is that if this repeated content goes out with the RSS feed, it just looks like an extra paragraph of unnecessary text. So, basically, I'm looking for a display:none equivalent for what goes into the RSS feed.

  2. Kafkaesqui

    Posted 7 years ago #

    It would be simple (well!) to roll a plugin that removes this div from your feed's content.

    Post an example of the div class, and I'll put something together for you.

  3. ptvguy
    Member
    Posted 7 years ago #

    Thanks, Kafkaesqui. Here's what the code looks like when I place it in a post.

    <div class="shoutout">
    <p>
    ...this is some example text...
    </p>
    </div>

    Some posts have several "shoutouts" and some have only one. I don't think you'll need the CSS for it, but I'll post it for anyone who may be looking through the forum one day to figure out how to do this.

    .shoutout {
    float: right;
    width: 155px;
    margin-top: 10px;
    margin-right: 15px;
    padding: 0;
    }

    .shoutout p {
    font-family: "Trebuchet MS", Verdana, Arial, Helvetica, sans-serif;
    font-size: x-large;
    text-align: right;
    width: 150px;
    }

    By the way, I for one think that such a plugin could be quite useful. RSS feeds are (usually) presented as linear text even if the page formatting presents it differently.

  4. Kafkaesqui

    Posted 7 years ago #

    And here's what I've come up with...

    Exclude DIV from RSS plugin:
    Download plugin | View source

    The class (or id) attribute value for the div is defined through the $class_id variable, which is set by default in the plugin to "shoutout".

    Did some testing but of course only real world banging will show up potential bugs in my pattern matching.

  5. ptvguy
    Member
    Posted 7 years ago #

    Awesome work, Kaf. I tried it out on my blog, and it did exactly what I needed. I went to my RSS reader prior to installing it and brought up my feed--which, of course, included my "shoutouts." Then, after installing it, I refreshed the feed and they were all gone. Thank you very much. I knew that it was something simple, but I have no experience with the coding for the WordPress hooks.

    I think that it's worth releasing as a regular plugin. It has potential to be extremely useful. Here are some possible notes for public release:

    • Needs an admin interface to allow for resetting the $class_id outside the code itself.
    • Probably doesn't need to check for the DIV in the excerpt part.
    • Might want to expand for other identified elements such as SPAN.
    • Needs a spiffy plugin name like ClassBlocker or NoClassFeed. ;>

    Anyway, thanks again for your time and expertise.

  6. Kafkaesqui

    Posted 7 years ago #

    * Needs an admin interface to allow for resetting the $class_id outside the code itself.

    I'm not a fan of plugins with single setting option pages. But if I do take it *more* public, I'll certainly look at ways of expanding the feature set, which would require a number of settings to play with.

    * Probably doesn't need to check for the DIV in the excerpt part.

    Actually it does -- at least, to my way of thinking. Most probably do not provide an excerpt and allow WordPress to take it from the content. And in the event part or all of a div is displayed with the excerpt, it could be confusing since it would not even be blocked off by the div (tags having been stripped from the excerpt).

    In any case, it certainly doesn't hurt anything running on the excerpt.

    * Might want to expand for other identified elements such as SPAN.

    Checked for expanding that options page.

    * Needs a spiffy plugin name like ClassBlocker or NoClassFeed. ;>

    We'll see...

  7. ptvguy
    Member
    Posted 7 years ago #

    Please don't construe my previous comments as a complaint of any kind. I'm more than happy with the plugin as is. I actually expected to get raw code that I would have to integrate into the PHP myself. You made it incredibly easy, and I truly appreciate that.

  8. Kafkaesqui

    Posted 7 years ago #

    "Please don't construe my previous comments as a complaint of any kind."

    Not at all! I understood it to be constructive feedback, something I always like to get.

  9. Reggolb
    Member
    Posted 7 years ago #

    Very useful plugin, exactly what I've been looking for. Thanks a lot!

  10. Varsity
    Member
    Posted 7 years ago #

    Just what I need. :-) Only I'm using span instead of div; I've tweaked the code to account for this myself, but a better solution would be adding another variable that lets you specify an element to exclude, or if left blank filter everything.

Topic Closed

This topic has been closed to new replies.

About this Topic