Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #615183

    Hi,

    I’m using a code-snippet plugin, to add snippets to ENFOLD’s function.php.
    There I added a found snippet:

    //Register tag cloud filter callback
    add_filter('widget_tag_cloud_args', 'tag_widget_limit');
    //Limit number of tags inside widget, exclude ID34, sort by count
    function tag_widget_limit($args){
     //Check if taxonomy option inside widget is set to tags
     if(isset($args['taxonomy']) && $args['taxonomy'] == 'post_tag'){
      $args['number'] = 12; //Limit number of tags
      $args['exclude'] = 34;
      $args['orderby'] = 'count';
      $args['order'] = 'DESC';
     }
     return $args;
    }

    It works fine for the tag cloud widget.

    I’m not so good in PHP, so could you please help me how to extend this snippet, so that a tag ID34 is excluded below a single post?
    Or doesn’t this work via a code-snippet plugin and do I need to edit a theme file for this?

    Thank you.

    #615998

    Hi Chris,

    It looks like it should exclude just that post, could you please provide us with a temporary admin login so that we can take a closer look? You can post the details in the Private Content section of your reply.

    Best regards,
    Rikard

    #616386

    Hi Rikard,

    thank you, but I found last night a snippet in the WP forum, which works perfectly:

    function mtstheme_filter_tags( $term_links ) {
        $result = array();
        $exclude_tags = array( 'getestet' );
        foreach ( $term_links as $link ) {
            foreach ( $exclude_tags as $tag ) {
                if ( stripos( $link, $tag ) !== false ) continue 2;
            }
            $result[] = $link;
        }
        return $result;
    }
    add_filter( "term_links-post_tag", 'mtstheme_filter_tags', 100, 1 );  

    in case someone needs this, too.
    “getestet” is my tag, that should not appear below the single post view (no matter what post).

    I put this snippet in my Code-Snippet-Plugin instead of working with the theme’s original functions.php :-)

    #617289

    Hi Chris,

    Ok great, glad you found a solution and thanks for sharing it :-)

    Regards,
    Rikard

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