• I use mailchimp to send out my new posts by email via RSS but have run into a problem where tablepress tables are not showing up correctly formatted (columns are squished). Mailchimp and tablepress support can’t help, so I’m trying to find a work-around.

    One idea I had was to duplicate my post containing the full table and delete multiple columns to trim it down. The goal would be for the post on the blog containing the full table to be available to users, but for the email that goes out to contain the trimmed table. To do that, I’d need a way to copy the code from the trimmed table post and insert it into RSS, and to delete the full table post that will already be in the RSS feed. Is there an easy way to do this? Or a better solution?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Moderator bcworkz

    (@bcworkz)

    No need to literally copy existing table HTML, alter, then replace original. You can filter the RSS output as it’s being generated. Refer to Customizing Feeds. You could alter the template code to filter table content after it is fetched from the DB but before it is output, altering it in any way you see fit.

    Modifying HTML through PHP string functions is far from ideal, but as long as the table structures are consistent it should work OK.

    Thread Starter savingyourtail

    (@savingyourtail)

    Thank you for the suggestion. I agree, that seems like a better approach. From reading on this, the steps to set up a custom RSS template make sense, but the PHP coding may be a challenge since I have little experience with it. Are you aware of any plugins that might ease the process of doing this?

    Moderator bcworkz

    (@bcworkz)

    Sorry, I’m unaware of such a plugin. I’m skeptical you’d find one since your goal is rather unique.

    I’m afraid my earlier suggestion was misleading. Apologies. The feed template is mainly for properly formatting the feed’s XML structure. The only part affecting actual post content is the call to get_the_content_feed(). If you want to alter post content in a feed, you wouldn’t make a custom feed template. Instead you’d use the “the_content_feed” filter hook to alter the actual content.

    You would need to find and remove all the undesired <td> elements in a table. One’s initial inclination might be to use string manipulation functions, which would work but is not ideal. A better approach would be to use DOMDocument class methods to manipulate the HTML DOM structure. Unfortunately this approach is more difficult to comprehend. But it would result in more robust, less fragile code. Since anything PHP is a challenge for you, sticking with string manipulation would completely justified. But if you’re up for an even greater challenge… ??

    • This reply was modified 6 months, 1 week ago by bcworkz. Reason: link fixed
    Thread Starter savingyourtail

    (@savingyourtail)

    Thanks for the ideas. You mentioned that I wouldn’t want to make a custom feed template after all. What file would I need to insert the code to call get_the_content_feed() and modify it so that the modified output shows up in the RSS feed?

    Moderator bcworkz

    (@bcworkz)

    It’s generally a bad idea to modify any code that’s not your own. I recommend creating your own custom plugin. It’s not as difficult as it might sound. It’s mainly a matter of having the right comment header and placing the file in the /plugins/ folder (or in its own sub-folder below /plugins/). Then include whatever PHP code you need to the file.

    I just realized I botched the link for the “the_content_feed” filter hook doc page in my last reply. It’s fixed now. My second error in this one thread. Apologies again. I don’t blame you if you don’t trust anything I say now.

    You wouldn’t actually call get_the_content_feed(). While it would return the content you want to modify, modifying the returned content will not affect the actual feed. To alter actual feed content, you would add a callback function to the filter “the_content_feed”. Your callback will be passed the current post content. Anything your callback returns will become the feed’s content. Check the user contributed example at the bottom of the previously linked doc page. The example simply adds a word count phrase to the end of the content. Your task will be more involved, but the basic filter hook structure is the same.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘RSS feed editing’ is closed to new replies.