Kategorien
Allgemein

Updating the URL in your wordpress feed

Today I noticed that my feed did not have the correct URL in the element atom:link because I run my installation of wordpress behind a reverse proxy. There are several things that can go wrong when using this setup, and this seems to be another one which is not documented anywhere…?

I added a new filter to my theme functions:

add_filter('self_link', 'CustomFeedUrlFilter', $priority = 10);
function CustomFeedUrlFilter($url) {
    return home_url() . '/feed/';
}

I’m now pulling the URL I configured as my WP_HOME from the database and overwrite any value coming from the original installation. This is possible because wordpress already runs the link through the filter self_link when generating the feed.

I don’t know why it’s so complicated to run behind a reverse proxy, but I hope this will get easier in the future. It’s the default setup when using containers, which means basically all cloud infrastructure at this point. I think there are some more things still broken, because sometimes I get redirected to the wrong URLs when I click links in the admin UI, i.e. when moderating comments. 🤷‍♂️