How to add custom feed to Sage 9

This is my first try with custom feeds in WP. So, I’m not sure if this is a Sage or simple WP question.

I created the feed this way:

# filters.php
add_action('init', function () {
    add_feed('campaign', 'campaignCallback');
});

function campaignCallback(){
    include \App\template_path(locate_template('views/partials/rss-newsletter.blade.php'));
}

# views/partials/rss-newsletter.blade.php
# with same content than wp/wp-includes/feed-atom.php

The feed URL is working but returns empty. It seems like blade template rss-newsletter.blade.php is not loaded. Could be?

[EDIT] Seems to be a WP issue, not Sage. Sorry for the off topic. Anyway, if anyone can provide a working example of add_feed() in Sage I will be eternally grateful. I have been diving in documentation for hours, with no luck.

1 Like

Have a look here: Manually render blade template in functions.php

This should work:

function campaignCallback() {
  echo \App\template('partials/rss-newsletter');
}
1 Like

You’re right. Also, I forgot to add namespace to add_feed(). This work:

add_action('init', function () {
    add_feed('campaign', __NAMESPACE__ . '\\campaignCallback');
});

function campaignCallback() {
    // header( 'Content-Type: application/rss+xml' );
    echo \App\template('partials/rss-campaign');
}
1 Like

This topic was automatically closed after 42 days. New replies are no longer allowed.