15 best creative shortcodes to use on your WordPress

15 best creative shortcodes to use on your WordPress
The shortcodes are part of WordPress for a long time , and one of the best ways to pull information directly to your pages and your blog posts . Recently colleagues from wptuts have to know some interesting shortcodes that we will use in our article today . With Shortcodes WordPress , it is possible to be extremely creative , especially if we use the WordPress Shortcodes API , so we pull information from external sources to the blog.

15 best creative shortcodes to use on your WordPress
PDFs are used on the Internet for various purposes, including documentation , but unfortunately , but many fewer users try it end up being required to install applications to achieve view the PDFs available on the Internet , which makes usually end up not read . Fortunately , Google Docs offers a PDF viewer that solves this problem . This plugin courtesy of Noscope offers the possibility to link directly to a Google Docs viewer, just by entering the link to the PDF in shortcode parameter .
function pdflink($attr, $content) {
    if ($attr[‘href’]) {
        return ‘<a class=”pdf” href=”http://docs.google.com/viewer?url=’ . $attr[‘href’] . ‘”>’.$content.'</a>’;
    } else {
        $src = str_replace(“=”, “”, $attr[0]);
        return ‘<a class=”pdf” href=”http://docs.google.com/viewer?url=’ . $src . ‘”>’.$content.'</a>’;
add_shortcode(‘pdf’, ‘pdflink’);
In fact , with some tweaks , this shortcode can be used as a viewer for other types of files , such as PowerPoint presentations and Word documents. You can store these files in your Google Docs library , save the file, print it or just edit it.
This shortcode in particular is very easy to use with only one parameter: the link to your PDF. Like this:
[pdf=http://manuals.info.apple.com/en_US/Enterprise_Deployment_Guide.pdf]Link text.[/pdf]
Make money online with blogs is undoubtedly an increasingly present reality , but it requires both forms of monetization so that this project can give your profits. Many bloggers do it through ads , usually Google ads. With this simple shortcode you can put your Adsense ads , wherever they want in your posts.
function showads() {
    return ‘<script type=”text/javascript”><!–
google_ad_client = “<em>your client id</em>”;
google_ad_slot = “<em>your ad slot id</em>”;
google_ad_width = <em>width</em>;
google_ad_height = <em>height</em>;
<script type=”text/javascript”
add_shortcode(‘adsense’, ‘showads’);
If you do not use Google Adsense to make money, can the same shortcode for affiliate programs or other forms of monetization that use .
To display an ad in an article in your blog , you only need to copy and paste the following shortcode to where you want the ad to appear .
[ Adsense ]
If you have a team working with you on your blog , communication between you is key. Using this shortcode to leave messages that only blog administrators can see , you can keep your communication in day. This shortcode puts his notes in class “note” , allowing you to stylize the notes using CSS .
function sc_note ( $ atts , $ content = null) {
     if ( current_user_can ( ‘ publish_posts ‘))
        return ‘ < div class = ” note”> ‘ $ content ‘< / div >’. . ;
    return ‘ ‘ ;
add_shortcode ( ‘ Note’ ‘ sc_note ‘);
To use this shortcode , simply wrap your note using the tags [ note ]
[ Note ] <em> Your notes </ em > [ / note ]
4. overshadow MAIL ADDRESS
No one likes spam , and put your email address visible on the Internet does not help much . However, you will certainly need to show your email to your readers , and using this shortcode you can overshadow him and avoid being caught in the net and e-mail for spam capture scripts.
function munge_mail_shortcode ( $ atts , $ content = null) {
    for ($ i = 0; $ i < strlen ( $ content ) ; $ i ++ ) . encodedmail $ = “& #” . ord ( $ content [ $ i] ) . ‘;’ ;
    return ‘ <a href=”mailto:’.$encodedmail.'”> ‘ $ encodedmail ‘ </a> ‘ . . ;
add_shortcode ( mailto “,” munge_mail_shortcode ‘);
This shortcode basically encodes your email address in HTML characters instead of text. Although not 100 % anti -spam is a great way to keep your email away from these problems. To use this shortcode , simply wrap your email address in the tags [ mailto ] as shown below.
[ Mailto ] myemail@example.com [ / mailto ]
Many templates for WordPress shortcodes to include YouTube – or a similar service – which means adding videos is as simple as clicking a button and put the video ID . However , with this amazing shortcode , you can add maps from Google Maps on your blog, simply put the URL provided by the map itself page.
function fn_googleMaps($atts, $content = null) {
      “width” => ‘640’,
      “height” => ‘480’,
      “src” => ”
   ), $atts));
   return ‘<iframe width=”‘.$width.'” height=”‘.$height.'” frameborder=”0″ scrolling=”no” marginheight=”0″ marginwidth=”0″ src=”‘.$src.'”></iframe>’;
add_shortcode(“googlemap”, “fn_googleMaps”);
There are only three attributes to use this shortcode : width, height and the URL. The first two are fairly obvious , and the third, the URL of the map, you can pull directly from Google Maps.
[ Googlemap width = “600 ” height ” 360 ” src = ” http : //google.com/maps/ ie = … ” ]
This shortcode allows you to embed an RSS feed via a simple shortcode using RSS tools integrated in WordPress itself . This amazing shortcode requires only two parameters to function properly.
function readRss($atts) {
    “feed” => ‘http://’,
      “num” => ‘1’,
    ), $atts));  
    return wp_rss($feed, $num);
add_shortcode(‘rss’, ‘readRss’);
To work properly , place the URL of your RSS feed in the attribute “feed” , and the number of posts you want to display the attribute ” a ” .
[ Rss feed = ” http://feeds.feedburner.com/webdesigntutsplus ” num = “3” ]
Twitter introduced a share button some time ago , which allows users connected on Twitter , share posts from your blog with one click . Add this button in your articles is also very simple, especially if you use this powerful shortcode . This shortcode allows you to add a Twitter sharing button in your articles, using a simple shortcode .
function twitter( $atts, $content=null ){
/* Author: Shyam Prasad
 * URL: http://www.online-seva.com/
        ‘url’ => null,
        ‘counturl’ => null,
        ‘via’ => ”,
        ‘text’ => ”,
        ‘related’ => ”,
        ‘countbox’ => ‘none’, // none, horizontal, vertical  
    ), $atts));  
    // Check for count url and set to $url if not provided
    if($counturl == null) $counturl = $url;  
    $twitter_code = <<    <script src=”http://platform.twitter.com/widgets.js” type=”text/javascript”><!–mce:0–></script>
<a class=”twitter-share-button” href=”http://twitter.com/share”></a>
    return $twitter_code;  
add_shortcode(‘t’, ‘twitter’);
There are two uses for this shortcode . The simplest form is shown below , which shows the small button in your articles.
[ Url = t ‘ get_permalink (); ‘]
If you want to use a button with counter, you just have to set a parameter to set whether a horizontal or vertical button.
[ T countbox = ” horizontal / vertical” ]
Finally , you can also define which Twitter accounts indicate after the user to perform your tweet in order to get more followers on Twitter.
[ T related = ‘ connorturnbull : Author , escolawordpress : Sister Site ” ]
A trend that has increased in recent times is to show content only to registered members, and often these contents are called “Premium”. WordPress has a very good user management system, and along with this shortcode can help you increase the number of users on your site / blog. Using this shortcode any content displayed between the tags is only visible to registered users on the site.
If you have concerns in relation to their RSS feeds, this shortcode will also hide the premium content of its general Feed.
add_shortcode ( ‘member’, ‘member_check_shortcode’);
function member_check_shortcode ($ atts, $ content = null) {
     if (is_user_logged_in () &&! is_null ($ content) &&! is_feed ())
        return $ content;
    return ”;
Using the tags [member] you can hide your public content in general.
[Member] My super secret content. [/ Member]
Related Articles are one of the best ways for you to convince your users to read more of your blog content. You can implement related products in your template using plugins, but this shortcode can make it even working , and can even be customized through its attributes.
function related_posts_shortcode( $atts ) {
        ‘limit’ => ‘5’,
    ), $atts));  
    global $wpdb, $post, $table_prefix;  
    if ($post->ID) {
        $retval = ‘<ul>’;
        // Get tags
        $tags = wp_get_post_tags($post->ID);
        $tagsarray = array();
        foreach ($tags as $tag) {
            $tagsarray[] = $tag->term_id;
        $tagslist = implode(‘,’, $tagsarray);  
        // Do the query
        $q = “SELECT p.*, count(tr.object_id) as count
            FROM $wpdb->term_taxonomy AS tt, $wpdb->term_relationships AS tr, $wpdb->posts AS p WHERE tt.taxonomy =’post_tag’ AND tt.term_taxonomy_id = tr.term_taxonomy_id AND tr.object_id  = p.ID AND tt.term_id IN ($tagslist) AND p.ID != $post->ID
                AND p.post_status = ‘publish’
                AND p.post_date_gmt < NOW()
            GROUP BY tr.object_id
            ORDER BY count DESC, p.post_date_gmt DESC
            LIMIT $limit;”;  
        $related = $wpdb->get_results($q);
        if ( $related ) {
            foreach($related as $r) {
                $retval .= ‘<li><a title=”‘.wptexturize($r->post_title).'” href=”‘.get_permalink($r->ID).'”>’.wptexturize($r->post_title).'</a></li>’;
        } else {
            $retval .= ‘
    <li>No related posts found</li>’;
        $retval .= ‘</ul>’;
        return $retval;
You can pull related articles from your blog simply by using the shortcode which is below. Alternatively , you can limit the number of posts to indicate using the parameters as shown in the second example .
This is a very interesting shortcode that allows you to display the last image attached to a particular item using a simple shortcode . Obviously , WordPress has its own tool images, but that does not always work correctly depending on the type of work you want to develop . Fortunately, this feature allows you to upload an image and pull the same image to the place that chooses, provided that this image is the last to be charged.
function sc_postimage($atts, $content = null) {
        “size” => ‘thumbnail’,
        “float” => ‘none’
    ), $atts));
    $images =& get_children( ‘post_type=attachment&post_mime_type=image&post_parent=’ . get_the_id() );
    foreach( $images as $imageID => $imagePost )
    $fullimage = wp_get_attachment_image($imageID, $size, false);
    $imagedata = wp_get_attachment_image_src($imageID, $size, false);
    $width = ($imagedata[1]+2);
    $height = ($imagedata[2]+2);
    return ‘<div class=”postimage” style=”width: ‘.$width.’px; height: ‘.$height.’px; float: ‘.$float.’;”>’.$fullimage.'</div>’;
add_shortcode(“postimage”, “sc_postimage”);
As in almost all shortcodes that we talked about , this joins the group of the simplest to use. The tag to be used alone , or with a specified size to customize the extension.
[ Postimage size = ” a ” float = “left / right” ]
This amazing shortcode allows you to soak a very interesting media type in your projects online. There is a YouTube video , or any HTML5 or Flash effect. In fact , they are even graphics.
Although graphics can be extremely boring , Google Charts API allows you to create extremely interesting graphics, even more so if you make these gorgeous graphics in a simple shortcode for quick use in WordPress . Experience using this shortcode is still a little laboratory compared to others, but certainly it will save you a lot of time in the long run .
function chart_shortcode( $atts ) {
        ‘data’ => ”,
        ‘colors’ => ”,
        ‘size’ => ‘400×200’,
        ‘bg’ => ‘ffffff’,
        ‘title’ => ”,
        ‘labels’ => ”,
        ‘advanced’ => ”,
        ‘type’ => ‘pie’
    ), $atts));  
    switch ($type) {
        case ‘line’ :
            $charttype = ‘lc’; break;
        case ‘xyline’ :
            $charttype = ‘lxy’; break;
        case ‘sparkline’ :
            $charttype = ‘ls’; break;
        case ‘meter’ :
            $charttype = ‘gom’; break;
        case ‘scatter’ :
            $charttype = ‘s’; break;
        case ‘venn’ :
            $charttype = ‘v’; break;
        case ‘pie’ :
            $charttype = ‘p3’; break;
        case ‘pie2d’ :
            $charttype = ‘p’; break;
        default :
            $charttype = $type;
    if ($title) $string .= ‘&chtt=’.$title.”;
    if ($labels) $string .= ‘&chl=’.$labels.”;
    if ($colors) $string .= ‘&chco=’.$colors.”;
    $string .= ‘&chs=’.$size.”;
    $string .= ‘&chd=t:’.$data.”;
    $string .= ‘&chf=’.$bg.”;  
    return ‘<img title=”‘.$title.'” src=”http://chart.apis.google.com/chart?cht=’.$charttype.”.$string.$advanced.'” alt=”‘.$title.'” />’;
add_shortcode(‘chart’, ‘chart_shortcode’);
To use this shortcode , it is important that you have some knowledge about how the Google Charts API. If possible, keep including the API documentation around, to get a sense of how things work .
Once you have some knowledge , the parameters are certainly simple to use, in particular data values, color , background color , size , title, among others.
[chart data=”41.52,37.79,20.67,0.03″ bg=”F7F9FA” labels=”Reffering+sites|Search+Engines|Direct+traffic|Other” colors=”058DC7,50B432,ED561B,EDEF00″ size=”488×200″ title=”Traffic Sources” type=”pie”]
In some cases, you may want to display text that is rendered negatively by the editor of your WordPress blog. With this shortcode , you can remove the automatic formatting of text WordPress .
function my_formatter($content) {
    $new_content = ”;
    $pattern_full = ‘{([raw].*?[/raw])}is’;
    $pattern_contents = ‘{[raw](.*?)[/raw]}is’;
    $pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);  
    foreach ($pieces as $piece) {
        if (preg_match($pattern_contents, $piece, $matches)) {
            $new_content .= $matches[1];
        } else {
            $new_content .= wptexturize(wpautop($piece));
    return $new_content;
remove_filter(‘the_content’, ‘wpautop’);
remove_filter(‘the_content’, ‘wptexturize’);  
add_filter(‘the_content’, ‘my_formatter’, 99);
The use is extremely simple and you just need to soak the text in the tags [ raw] the shortcode .
[Raw ] My unformatted text [ / raw ]
Many bloggers love to show how many articles are published to your blog , or how many comments have been posted, or other statistics. With this shortcode , you can pull a wide range of statistics for a page or article if desired .
add_shortcode(‘wcs_count’, ‘wcs_count_shortcode_handler’);
function wcs_count_shortcode_handler($atts)
    // extract parameters
    $parms = shortcode_atts(array(
        ‘type’ => ‘posts’,
        ‘format’ => ‘true’,
        ‘extra’ => ‘1’,
        ), $atts);  
    $type = strtolower($parms[‘type’]);
    $format = strtolower($parms[‘format’]);
    $extra = $parms[‘extra’];  

    // process t/f options
    $b_format = false;
    if (($format == ‘yes’) || ($format == ‘y’) ||
        ($format == ‘true’) || ($format == ‘1’))
    {$b_format = true;}  
    // exit
    return wcs_get_count($type, $b_format, $extra);
function wcs_get_count($type=’posts’, $format=’1′, $extra=’1′)
    // TYPES:
    // posts, posts_by_author, pages, tags, categories
    // users, ms_users, blogroll, blogroll_categories, commenters
    // comments, comments_pending, comments_spam, comments_pingback
    // comments_by_user, comments_by_nicename, comments_by_email
    // comments_per_post  
    // $extra is used with:
    // posts_by_author, comments_by_user, comments_by_nicename, comments_by_email
    // comments_per_post
// init
    global $wpdb;
    $type = strtolower($type);
    $count = 0;  
    // process
        case ‘posts’: // published
        $count = wp_count_posts(‘post’);
        $count = $count->publish;
        // options: publish, future, draft, pending, private, trash, auto-draft, & inherit
        case ‘posts_by_author’: // use $extra for user/author id
        case ‘posts_by_user’:
        $query = “SELECT COUNT(*) FROM $wpdb->posts “;
        $where = “WHERE post_type=’post’ AND post_status=’publish’ AND post_author=’$extra'”;
        $count = $wpdb->get_var($query . $where);
        // alternative method is: count_user_posts()
        case ‘pages’: // published
        $count = wp_count_posts(‘page’);
        $count = $count->publish;
        case ‘tags’:
        $count = wp_count_terms(‘post_tag’);
        case ‘categories’:
        $count = wp_count_terms(‘category’);
case ‘users’:
        $count = count_users();
        $count = $count[‘total_users’];
        case ‘ms_users’: // multi-site
        $count = get_user_count();
        case ‘blogroll’:
        $query = “SELECT COUNT(*) FROM $wpdb->links “;
        $where = “WHERE link_visible=’Y'”;
        $count = $wpdb->get_var($query . $where);
        case ‘blogroll_categories’:
        $count = wp_count_terms(‘link_category’);
        case ‘commenters’:
        $query = “SELECT COUNT(DISTINCT comment_author) FROM $wpdb->comments “;
        $where = “WHERE comment_approved=’1′ AND comment_type=””;
        $count = $wpdb->get_var($query . $where);
        case ‘comments’:
        $query = “SELECT COUNT(*) FROM $wpdb->comments “;
        $where = “WHERE comment_approved=’1′ AND comment_type=””;
        $count = $wpdb->get_var($query . $where);
        case ‘comments_pending’:
        $query = “SELECT COUNT(*) FROM $wpdb->comments “;
        $where = “WHERE comment_approved=’0′ AND comment_type=””;
        $count = $wpdb->get_var($query . $where);
        case ‘comments_spam’:
        $query = “SELECT COUNT(*) FROM $wpdb->comments “;
        $where = “WHERE comment_approved=’spam’ AND comment_type=””;
        $count = $wpdb->get_var($query . $where);
        case ‘comments_pingback’:
        case ‘comments_pingbacks’:
        case ‘comments_trackback’:
        case ‘comments_trackbacks’:
        $query = “SELECT COUNT(*) FROM $wpdb->comments “;
        $where = “WHERE comment_approved=’1′ AND comment_type=’pingback'”;
        $count = $wpdb->get_var($query . $where);
        case ‘comments_by_user’: // use $extra for user_id
        $query = “SELECT COUNT(*) FROM $wpdb->comments “;
        $where = “WHERE comment_approved=’1′ AND comment_type=” AND user_id=’$extra'”;
        $count = $wpdb->get_var($query . $where);
        case ‘comments_by_author’: // use $extra for author nicename (case INsensitive)
        case ‘comments_by_nicename’:
        $query = “SELECT COUNT(*) FROM $wpdb->comments “;
        $where = “WHERE comment_approved=’1′ AND comment_type=” AND comment_author=’$extra'”;
        $count = $wpdb->get_var($query . $where);
        case ‘comments_by_email’: // use $extra for author email (case INsensitive)
        $query = “SELECT COUNT(*) FROM $wpdb->comments “;
        $where = “WHERE comment_approved=’1′ AND comment_type=” AND comment_author_email=’$extra'”;
        $count = $wpdb->get_var($query . $where);
        case ‘comments_per_post’: // $extra is decimal place precision (0 for integer only)
        // posts
        $posts_count = wp_count_posts(‘post’);
        $posts_count = $posts_count->publish;
        // comments
        $query = “SELECT COUNT(*) FROM $wpdb->comments “;
        $where = “WHERE comment_approved=’1′ AND comment_type=””;
        $comment_count = $wpdb->get_var($query . $where);
        // average
        return round($comment_count / $posts_count, $extra);  
        $count = 0;
    // exit
    if ($format) {$count = number_format_i18n($count);}
    return $count;  
     Copyright © 2011 Gizmo Digital Fusion (http://wpCodeSnippets.info)
     you can redistribute and/or modify this code under the terms of the
     GNU GPL v2: http://www.gnu.org/licenses/gpl-2.0.html
Shortcode to work , you only have to define the type of statistics you want to display by selecting the “type” attribute .
[ Wcs_count type = “post ” ]
14. SHOW Flickr images
Many bloggers use Flickr to manage your photos . A seal Flickr is a small widget that allows you to view galleries from Flickr on a page or article . With this shortcode , you can do so in seconds.
function flickr_badge_shortcode($atts, $content=NULL){  
$query_atts = shortcode_atts(array(‘count’ => ‘6’, ‘display’ => ‘latest’, ‘source’ => ‘user’, ‘size’ => ‘t’, ‘user’ => ”, ‘layout’ => ‘x’, ‘tag’ => ”, ‘group’ => ”, ‘set’ => ”), $atts);  
return sprintf(‘
<div class=”flickr_badge”>
<script src=”http://www.flickr.com/badge_code_v2.gne?%s” type=”text/javascript”></script><span style=”position:absolute;left:-999em;top:-999em;visibility:hidden” class=”flickr_badge_beacon”><img src=”http://geo.yahoo.com/p?s=792600102&t=be99960558f114c2debcedd31896babd&r=http%3A%2F%2Fwp.tutsplus.com%2Farticles%2Fgeneral%2Fresource-roundup-20-creative-shortcodes-to-use-in-your-projects%2F&fl_ev=0&lang=pt&intl=uk” width=”0″ height=”0″ alt=””></span></div> 
‘, $content, http_build_query($query_atts));
add_shortcode(‘flickrbadge’, ‘flickr_badge_shortcode’);
This badge Flickr includes a number of parameters that need to be defined in the shortcode . The parameter “count” tells the shortcode number of images to be shown , the parameter “source ” describes the terms of looking for images (such as user, group , etc.) and the parameter “display” decides to show the form of pictures random , or just the latest .
[flickrbadge count=”4″ layout=”h” display=”latest” size=”t” source=”all_tag” tag=”fish”]Here’s the latest fish[/flickrbadge]
No blog moves alone, and want the author to work exclusively on it, or a job itself , the more likely it is to have to pay some expenses to keep in the air. Although the vast majority of bloggers monetize their projects with advertising , others take advantage of their community through PayPal donations. This shortcode allows you to pull a donation link at any time , and it’s super simple to style according to your blog.
function donate_shortcode( $atts ) {
        ‘text’ => ‘Make a donation’,
        ‘account’ => ‘REPLACE ME’,
        ‘for’ => ”,
    ), $atts));  
    global $post;  
    if (!$for) $for = str_replace(” “,”+”,$post->post_title);  
    return ‘<a class=”donateLink” href=”https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=’.$account.’&item_name=Donation+for+’.$for.'”>’.$text.'</a>’;  
add_shortcode(‘donate’, ‘donate_shortcode’);
The donation shortcode is only prompted by a CSS class ” donateLink ” in order to show the way the donation link that you like best .


Please enter your comment!
Please enter your name here