0

I was wondering if it's possible to automatically show some text about a given category beneath the post. I'd like to be able to show some text beneath some (but not all) categories.

Use case: I'm using affiliate-links and want to make it clear for the visitors that I may receive commission on some links in a post. As a result I've created a category called "affiliate" and would like to show some information about what affiliate means. Instead of just copy/pasting the same description to the bottom of every post with affiliate links, I'd like a way to iterate the description at a later date and would therefore prefer a solution that shows the text based on the category.

Any ideas? Thanks in advance!

0

The simplest solution would be a simple filter on the_content:

function my_affiliates_descr($content) {
 if (is_single() && has_category('affiliate')) {
  $content .= 'This is an affiliate post';
 }
 return $content;
}
add_filter('the_content','my_affiliates_descr');

You could combine that with category_description() as suggested in a comment to the question to get:

function my_affiliates_descr($content) {
 if (is_single() && has_category('affiliate')) {
  $content .= category_description( get_category_by_slug('affiliate')->term_id );;
 }
 return $content;
}
add_filter('the_content','my_affiliates_descr');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.