Customizing the_tags output?

Try this:

$args = array(
    'taxonomy'   => 'post_tag',
    'hide_empty' => 0
);
$tags = get_terms( $args );
$class_name="my-custom-class-name";

if ( ! empty( $tags ) && ! is_wp_error( $tags ) ) {
    shuffle( $tags );   
    foreach( array_slice( $tags, 0, 6 ) as $tag ) {
        printf( '<a class="%1$s" href="https://wordpress.stackexchange.com/questions/223735/%2$s">%3$s</a>',
            sanitize_html_class( $class_name ),
            get_tag_link( $tag->term_id ),
            sprintf( __( '%s') , $tag->name )
        );
    }
}

Since there isn’t a RAND order option in get_terms() or get_the_tags(), what this does is:

  • Get all tags from the post_tags taxonomy
  • Shuffle the resulting array.
  • Slice the resulting array to 6 entries
  • Build links with your custom class