Home › Forums › Product Support Forums › Related Posts Pro for WordPress Support › Not displaying related posts › Reply To: Not displaying related posts
September 6, 2021 at 11:53 am
#34550
Keymaster
Thank you!
I have added the following custom code to the functions.php file in your actual theme directory:
function add_tags_to_rpp($post) {
// Tags
$tags = get_the_tags($post->id);
if ( $tags !== false && count($tags) > 0 ) {
$tags_output = '';
$tags = array_map(function($tag){return $tag->name;}, $tags);
$tags_output = '<p style="font-size: 11px;"><strong>Tags:</strong> ' . implode(', ', $tags) . '</p>';
$post->content = $tags_output . $post->content;
}
// Categories
$tags = get_the_category($post->id);
if ( $tags !== false && count($tags) > 0 ) {
$tags_output = '';
$tags = array_map(function($tag){return $tag->name;}, $tags);
$tags_output = '<p style="font-size: 11px;"><strong>Categories:</strong> ' . implode(', ', $tags) . '</p>';
$post->content = $tags_output . $post->content;
}
return $post;
}
add_filter( 'rpp_item_after_postprocessing', 'add_tags_to_rpp', 10, 1);
This will append the categories and tags list to the related posts content, where possible: https://i.imgur.com/khDVBRd.png