Create a gist now

Instantly share code, notes, and snippets.

[WordPress] Display random post tags.
<?php
$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="%2$s">%3$s</a>',
sanitize_html_class( $class_name ),
get_tag_link( $tag->term_id ),
sprintf( __( '%s') , $tag->name )
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment