[Resolved] Exclude a specific tag from the output of the tag-list

Home Forums Support [Resolved] Exclude a specific tag from the output of the tag-list

Home Forums Support Exclude a specific tag from the output of the tag-list

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1068204
    Heike

    Maybe my method is completely wrong, then I ask politely for a suitable solution:

    We use the Plugin WP Show Posts which allows the selection of posts to be displayed by a certain tag. Such tags are purely functional and without any meaning in terms of content. So I’m wondering if there is a way to hide one or more tags created for this purpose from appearing in the tag list of the posts meta?

    Thankful for any help,
    Heike

    #1068281
    Leo
    Staff
    Customer Support
    #1068293
    Heike

    Hi Leo,

    no – not the post should be excluded, that could be handled by WP Show Posts settings.
    I try to exclude the specific tag/tags from the tag list in the posts meta, i.e. a tag „test“ not to be shown in the list of other tags.

    #1068774
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    It doesn’t look like it’s possible using the core function. You would need to create your own function (https://wordpress.stackexchange.com/a/156336/90661) and then hook it into your WPSP list.

    #1070399
    Heike

    Hi Tom,

    thanks for going into this – and excuse me if my bad english and lack of knowledge about GP leads to misunderstandings.
    I try to be clearer, because the problem would exist even without WPSP.

    Maybe I’m totally wrong, but as far as I understand, WPSP has nothing to do with the tags (and other post metas) appearing within the header or footer of archives and single posts in the frontend of the website. This happens through GP customizer settings and GP template files (i.e. post-meta.php), isn’t it?
    The functions and hooks should then start there …

    #1071610
    Tom
    Lead Developer
    Lead Developer

    The theme uses get_the_tag_list(), which it looks like you can filter: https://wordpress.stackexchange.com/a/48736

    You could try this:

    add_filter( "term_links-post_tag", function( $term_links ) {
        $result = array();
        $exclude_tags = array( 'some tag', 'another tag', 'third tag' );
    
        foreach ( $term_links as $link ) {
            foreach ( $exclude_tags as $tag ) {
                if ( stripos( $link, $tag ) !== false ) continue 2;
            }
            $result[] = $link;
        }
    
        return $result;
    } );
    #1071949
    Heike

    Tom, you made my day! This works great!
    Personally, I find it very difficult to figure out which filter to use where. It may well be that I have more questions for you. Is there a tip on how to learn this?

    Thank you,
    Heike

    #1072786
    Tom
    Lead Developer
    Lead Developer

    This one was hard – had to Google around for a bit.

    Otherwise, I usually look in the core WP functions for available filters.

    Glad I could help! 🙂

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.