Display Tags After Blog Posts in WordPress

On a recent project, my customer wanted to display post tags on his blog articles.

Whilst this isn’t an option available in Divi, I have found that by adding some code to your functions.php file, the Tags will display just below the post content.

So, ideally, you are using a Child theme to ensure that you protect your Divi customisation from being overridden by an update. Either way, you should find your functions.php file under Appearance > Editor.

Simply add the code below to the file and jobs a good’un! (remember to always backup your site before you edit php files, just in case)

<?php

/**
 * Adds post tags below post content
 */
function tags_after_single_post_content($content) {
  $posttags = get_the_tags();
  if ($posttags) {
    $array = [];
    foreach($posttags as $tag) {
      $array[] = '<a href="/tag/' . $tag->slug . '/">' . $tag->name . '</a>';
    }
    $content .= 'Tags: ' . implode(', ', $array) . '<br>'; //Change Tags: to whatever you want it to say
  }
  return $content;
}
add_filter( 'the_content', 'tags_after_single_post_content');

?>

 

sumber: https://www.catarinabras.co.uk/display-tags-on-your-blog-posts/

Leave a Comment