Created
October 6, 2019 19:35
-
-
Save frankmeeuwsen/a9409c0fced66c8bb560bca9ac82f538 to your computer and use it in GitHub Desktop.
How to get a specific text at a specific category in your WordPress feed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dtd_rssclub($content) { | |
global $wp_query; | |
$postid = $wp_query->post->ID; | |
if(is_feed() && has_category('RSS-Club', $postid) ) { | |
$content = '<div>Dit is een geheim bericht voor iedereen. <a href="/rss-club">Lees alles over de RSS Club</a></div><br /><br />'.$content; | |
} | |
else { | |
$content = $content; | |
} | |
return $content; | |
} | |
add_filter('the_excerpt_rss', 'dtd_rssclub'); | |
add_filter('the_content_rss', 'dtd_rssclub'); |
Awesome! I will test this and report back! Oh and any comment on any platform is fine by me ;-)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there! I've yet to figure out how to 'correctly' respond to hidden posts, so I'm just going to comment here.
Below code should work. You might get away with hooking both filters to the very same callback function, as you've done above, but there's a slight catch: excerpts don't usually contain HTML, like hyperlinks, and thus aren't usually wrapped in paragraph tags (although all of that is filterable, too). I've chosen to treat excerpts separately.
In short:
the_content_rss
is deprecated; usethe_content_feed
instead (which actually accepts a second argument, but we don't need it)is_feed()
this filter should never get called outside of a feed context$post
; no need for$wp_query
$content = $content;
doesn't actually do anything; the entireelse
branch can be left out ($content
will only get modified if the condition istrue
)get_permalink( get_page_by_path( 'rss-club' ) )
returns an absolute, rather than a root-relative link; this ensures the link works inside all feed readers$content