Site logo

[Support request] entry meta shortcode

Home Forums Support [Support request] entry meta shortcode

Home Forums Support entry meta shortcode

  • This topic has 3 replies, 2 voices, and was last updated 5 years ago by David.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1701509
    Den

    Hi team,

    is there any way that I can use to show tags using a [shortcode]? (i want to show tags in between the articles)

    If yes, then How? Can you please describe the method 🙂

    Thanks in advance

    #1701931
    David
    Staff
    Customer Support

    Hi there,

    this stack answer provides the PHP to create a shortcode to display post Tags:

    https://stackoverflow.com/a/47105106

    #1702061
    Den

    Hi david,

    It worked 🙂

    But it only shows the text and that too as a bullet point. (that I don’t want)

    For example: DON’T WANT

    • Tag 1
    • Tag 2

    Example: WANT

    Tag 1, Tag 2

    I want the tags to be a link

    Here’s the code that i added on my functions.php

    function getTagList($classes = '') {
        global $post;
        $tags = get_the_tags($post->ID);
        $tagOutput = [];
    
        if (!empty($tags)) {
            array_push($tagOutput, '<ul class="tag-list '.$classes.'">');
            foreach($tags as $tag) {
                array_push($tagOutput, '<li>'.$tag->name.'</li>');
            }
            array_push($tagOutput, '</ul>');
        }
    
        return implode('', $tagOutput);
    }
    
    add_shortcode('tagsList', 'getTagList');
    #1702986
    David
    Staff
    Customer Support

    Try this instead:

    function db_taglist(){
        return get_the_tag_list('<span class="tags-links in-content">', ', ', '</span>');
    }
    add_shortcode('tagsList', 'db_taglist');
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.