the_permalink_rss 过滤器不起作用
annuncistar.it 的 RSS 提要无效,因为“&” RSS 源中不允许使用 char。 为了解决这个问题,我在functions.php 文件中添加了一个WordPress 过滤器。
function mp_permalink($permalink) {
$url = str_replace("&", "&", $permalink);
return $url;
}
add_filter('the_permalink_rss', 'mp_permalink');
不幸的是这个功能不起作用。原因可能是什么?
the RSS feed of annuncistar.it isn't valid because the "&" char is not allowed in RSS feeds.
In order to solve that issue I've added a WordPress filter in my functions.php file.
function mp_permalink($permalink) {
$url = str_replace("&", "&", $permalink);
return $url;
}
add_filter('the_permalink_rss', 'mp_permalink');
Unfortunately this function doesn't work. What could the reason be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 Feed URL 似乎附加了 Google Analytics 跟踪变量(utm_source 等)。通常,WordPress 提要 URL 看起来很简单(以我的为例):
但是,使用 Analytics 跟踪变量,它看起来像这样:
所以,我猜测您安装了一个正在更改提要 URL 的插件添加这些变量。不幸的是,当它作为 feed 源嵌入到 RSS feed 中时,URL 中的 & 符号不会被转义——我猜这是插件中的一个错误。
我猜想您的过滤器在插件更改原始提要之后不会运行。我不确定这是因为它在过滤器链中较早运行,还是因为分析插件针对不同级别的提要 URL。
无论哪种方式,解决方案都是禁用分析插件,或者至少禁用更改提要 URL 的部分,或者将其更新为正确转义 URL 以便在 RSS 提要 XML 中使用的版本。
Your feed URL seems to have Google Analytics tracking variables (utm_source, etc.) appended to it. Normally, a WordPress feed URL looks as simple as (to take mine as an example):
However, with Analytics tracking variables, it looks something like this:
So, I'm guessing that you have a plugin installed that is altering your feed URL to add these variables. Unfortunately, when it's being embedded in your RSS feed as the feed source, the ampersands in the URL aren't being escaped -- I'd guess this is a bug in the plugin.
I'd guess your filter isn't being run after the plugin changes the original feed. Whether that's because it's being run earlier in the filter chain or because the analytics plugin is targeting the feed URL at a different level, I'm not sure.
Either way, the solution will be to disable the analytics plugin, or at least the bit that alters the feed URL, or update it to a version that escapes the URL properly for use in the RSS feed XML.