Skip to content

Instantly share code, notes, and snippets.

@nfreear
Created October 24, 2014 08:42
Show Gist options
  • Save nfreear/54d064c42cbd037e4eee to your computer and use it in GitHub Desktop.
Save nfreear/54d064c42cbd037e4eee to your computer and use it in GitHub Desktop.
Shortcode wrapper [tagcloud] around WordPress core function: `wp_tag_cloud` ♡ ©The Open University ♡ https://github.com/IET-OU
<?php
/*
Plugin Name: IET WP tag cloud
Plugin URI: https://github.com/IET-OU/oer-evidence-hub-org
Description: Shortcode wrapper [tagcloud] around WordPress core function: `wp_tag_cloud` [LACE]
Author: Nick Freear [@IET-OU]
Author URI: https://github.com/IET-OU
Version: 0.1
*/
/**
* @link http://codex.wordpress.org/Function_Reference/wp_tag_cloud
* @copyright © Nick Freear, 23 October 2014.
*/
class IET_WP_Tag_Cloud_Plugin {
const SHORTCODE = 'tagcloud';
public function __construct() {
add_shortcode( self::SHORTCODE, array( &$this, 'shortcode' ));
}
public function shortcode( $attrs, $content = '', $name ) {
$classes = $this->get_classes( $attrs );
ob_start(); ?>
<div class="<?php echo $classes ?>">
<?php wp_tag_cloud( $attrs ) ?>
</div>
<?php
return ob_get_clean();
}
protected function get_classes( $attrs ) {
$classes[] = self::SHORTCODE;
$classes[] = str_replace( '_', '-', strtolower( __CLASS__ )); //'shortcode-' . self::SHORTCODE;
if ($attrs) {
foreach ($attrs as $key => $value) {
if (is_string( $value )) {
$classes[] = $key .'-'. $value;
}
}
}
return implode( ' ', $classes );
}
}
$iet_wp_tag_cloud = new IET_WP_Tag_Cloud_Plugin();
#End.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment