Skip to content

Instantly share code, notes, and snippets.

@dboutote
Created April 15, 2016 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dboutote/e47a79126efd9ff193abe886a6df3a71 to your computer and use it in GitHub Desktop.
Save dboutote/e47a79126efd9ff193abe886a6df3a71 to your computer and use it in GitHub Desktop.
[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