0

I have a system that works well for me where I can add a tag of affiliate to a post and then this code in my functions.php file adds a disclaimer to the beginning of the post:

/* Add disclaimer to top of POSTS that contain affiliate tag */ function tt_filter_the_content( $content ) { if (has_tag('affiliate')) $custom_content = '<hr><p><em>Disclosure: This post contains affiliate links and we may receive a referral fee (at no extra cost to you) if you sign up or purchase products or services mentioned.</em></p><hr>'; $custom_content .= $content; return $custom_content; } add_filter( 'the_content', 'tt_filter_the_content' );

I've been using this method for a while and it works great. However, I noticed that on my summary excerpts and my feed, it shows that disclaimer as well. That makes it a little messy and cuts away from a lot of the summary text showing up.

Is there a way to filter this out from being applied to the summary and my RSS feed?

3
  • Have you tried is_feed() -> codex.wordpress.org/Function_Reference/is_feed I am not sure how your summaries are build, but you could try checking the page where they show up... and only apply the disclaimer to the single details page -> is_single might work.
    – gdaniel
    Aug 8, 2017 at 19:32
  • I like where you're going with this @gdaniel... unfortunately, I'm not really as good with this stuff as I'd like to pretend I am. :-) Any help you could give on implementing that would be appreciated.
    – Jim
    Aug 8, 2017 at 20:34
  • Could I do something in the 3rd line to be something like: if (has_tag('affiliate')) AND is_single to specify to only put it on the single posts?
    – Jim
    Aug 8, 2017 at 20:37

1 Answer 1

0

You could do something like this:

/* Add disclaimer to top of POSTS that contain affiliate tag */
function tt_filter_the_content( $content ) {
    if (has_tag('affiliate') && is_single())
    $custom_content = '<hr><p><em>Disclosure: This post contains affiliate links and we may receive a referral fee (at no extra cost to you) if you sign up or purchase products or services mentioned.</em></p><hr>';
    $custom_content .= $content;
    return $custom_content;
}
add_filter( 'the_content', 'tt_filter_the_content' );

Now you are checking if the tag exists and if it's a single post. If this still shows up in the feed, then you can change the if statement to something like:

if ((has_tag('affiliate') && is_single()) && !is_feed())
1
  • You rock!! That first one did it! Thank you so much for your help!!
    – Jim
    Aug 8, 2017 at 23:50

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .