• Hi!

    On each tag, we can write a description and see it on the tag page.

    How can I display tag descriptions on posts?

    I want to change tags below posts from:

    Tags: tag1, tag2, tag3.

    to:

    Tags:

    tag1 – description
    tag2 – description
    tag3 – description

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello @serezh4,

    You can write below code in your theme’s function.php file:

    function show_tags_description()
    {
    $post_tags = get_the_tags();
    $separator = ‘, ‘;
    if (!empty($post_tags)) {
    foreach ($post_tags as $tag) {
    $output .= ‘term_id) . ‘”>’ . $tag->name . ‘‘ . ‘<p>’ . $tag->description . ‘</p>’ .$separator;
    }
    return trim(($output), $separator);
    }
    }

    After that, wherever you want to place tags and description, you have to add below code:
    if ( is_singular() ) :
    echo show_tags_description();
    endif;

    Please let me know if any query.

    Thanks.

    Thread Starter serezh4

    (@serezh4)

    Thanks! But I got error here:

    $output .= ‘term_id) . ‘”>’ . $tag->name . ‘‘ . ‘<p>’ . $tag->description . ‘</p>’ .$separator;

    “syntax error, unexpected ‘,'”

    Hello @serezh4,

    Yes, sorry it was type mistake in editor. Please try code as attached screenshot in below link:
    https://ufile.io/gnm65s97

    Please let me know if still any issue.

    Thanks.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show tag descriptions on posts’ is closed to new replies.