Best Smart Short Codes for WordPress

For every WordPress user short codes are the prime factor to save time and energy in a great manner. Short codes actually allow a person to perform even the most complex coding task in an easy way. You can simplify your work by inserting the short codes in your post editor. Initially Short codes were introduced with the launch of WordPress 2.5 to help the users to create few macrocodes to use between you content matter.

This is certainly a great way to craft prompt and dynamic features in you post instantly. You can try on creating a great ad spot or may be a call for action button in your posts.

Here we will be providing you the few smart shortcodes for wordpress that can be well utilized for creating instant additions in your post. In order to understand the optimum utilization of the short codes one needs to churn over his/her imagination process to come over the utilization power of these codes.

If you want to use the call-to-action button then you can make addition of something as provided below in you BlogSpot to make the button visible.

osCitas

 Generating a self-closing short code

One of the simplest kinds of short code for wordpress is the self-closing short code. Here we are making and attempt to create a simple link to our twitter account to add the short code afterwards in thye blog post. All the codes goes directly to functions.php which can be found in /wp-content/themes/your-theme/. In case, you don’t have a one then in that case just create it and place the code to it.

See the code below:

<?php
function button_shortcode() {
return ‘<a href=”http://twitter.com/filipstefansson” class=”twitter-button”>Follow me on Twitter!</a>”‘;
}
add_shortcode(‘button’, ‘button_shortcode’);
?>

Usage:

osCitas

In order to make this button much better then we can also make addition to add some parameters as well. Here we will be telling you the way to add two parameters in a short code for button styling and username of the twitter account.

See the code below:

<?php
function button_shortcode( $atts, $content = null ) {
extract( shortcode_atts( array(
‘account’ => ‘account’,
‘style’ => ‘style’
), $atts ) );
return ‘<a href=”http://twitter.com/’ . esc_attr($account) . ‘” class=”twitter-button ‘ . esc_attr($style) . ‘”>’ . $content . ‘</a>’;
}
add_shortcode(‘button’, ‘button_shortcode’);
?>

Usage:

osCitas
// Result: &lt;a href=”http://twitter.com/filipstefansson”>Follow me on Twitter!&lt;/a>

Here we are with a easy to customize button that can be easily linked to any of the twitter account.

Short Codes inside Widgets and Template Documents

It is obvious to have an urge to utilize these wonders short codes for widgets and templates. In order to activate the smart short codes in your widgets follow the code in function.php

See the code below:

add_filter(‘widget_text’, ‘do_shortcode’)

In order to insert a short code in your template document files follow the code below:

do_shortcode(“osCitas“);

Instant Usable short codes

Below we are providing you some the coolest and smart short codes for WordPress that can be utilized instantly

In case, if you are having a blog which is primarily focused on programming then you may probably want to be display the codes in the post as well.

function code_shortcode( $attr, $content = null ) {
$content = clean_pre($content); // Clean pre-tags
return ‘<pre”><code>’ .
str_replace(‘<‘, ‘<‘, $content) . // Escape < chars
‘</code></pre>’;
}
add_shortcode(‘code’, ‘code_shortcode’);

Usage:

1&lt;?php echo ‘Hello World!’; ?>

Implant Adsense anyplace in the post

With the short code provided below one can make addition of a Google advertisement at anyplace you wish to with simple use of ad sense.

See the code below:

function showads() {
return ‘<script type=”text/javascript”><!–
google_ad_client = “pub-3637220125174754”;
google_ad_slot = “4668915978”;
google_ad_width = 468;
google_ad_height = 60;
//–>
</script>
<script type=”text/javascript”
src=”http://pagead2.googlesyndication.com/pagead/show_ads.js”>
</script>
‘;
}
add_shortcode(‘adsense’, ‘showads’);

To implant codes in YouTube video

With the help of the short code provided below one can implant the You Tube videos into your blog posts.

See the code below:

function youtube($atts) {
extract(shortcode_atts(array(
“value” => ‘http://’,
“width” => ‘475’,
“height” => ‘350’,
“name”=> ‘movie’,
“allowFullScreen” => ‘true’,
“allowScriptAccess”=>’always’,
“controls”=> ‘1’,
), $atts));
return ‘<object style=”height: ‘.$height.’px; width: ‘.$width.’px”>
<param name=”‘.$name.'” value=”‘.$value.'”>
<param name=”allowFullScreen” value=”‘.$allowFullScreen.'”>
<param name=”allowScriptAccess” value=”‘.$allowScriptAccess.'”>
<embed src=”‘.$value.'” type=”application/x-shockwave-flash” allowfullscreen=”‘.$allowFullScreen.'” allowScriptAccess=”‘.$allowScriptAccess.'” width=”‘.$width.'” height=”‘.$height.'”></object>’;
}
add_shortcode(“youtube”, “youtube”);

Usage:

// Optional attributes: width, height, name, allowFullScreen, allowScriptAccess, controls

[youtube value=”http://www.youtube.com/watch?v=1aBSPn2P9bg”]

PayPal bequest Short code

The short code provided below will help you to provide links to your PayPal Account.

function donate_shortcode( $atts, $content = null) {
global $post;extract(shortcode_atts(array(
‘account’ => ‘your-paypal-email-address’,
‘for’ => $post->post_title,
‘onHover’ => ”,
), $atts));
if(empty($content)) {
$content=’Make A Donation’;
}return ‘<a href=”https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=’.$account.’&item_name=Donation for ‘.$for.'” title=”‘.$onHover.'”>’.$content.'</a>’;
}
add_shortcode(‘donate’, ‘donate_shortcode’);

Usage:

[donate]
[donate]Donate Now[/donate]
[donate account=”you@yoursite.com” onHover=”Thanks” for=”Title”]
[donate account=”you@yoursite.com” onHover=”Thanks” for=”Title”]Donate Now[/donate]

Author’s Short Code

The last short code that we want to provide is the special one to help the authors to utilize the short code in their blogs. With the help of this smart short code, one can create some personal notes in the post that will only be visible to the author.

See the code below:

function sc_note( $atts, $content = null ) {
if ( current_user_can( ‘publish_posts’ ) )
return ‘<div>’.$content.'</div>’;
return ”;
}
add_shortcode( ‘note’, ‘sc_note’ );

Conclusion

By providing all the helpful smart codes for WordPress to you above, we feel glad and delighted to help our visitors using smart ways of implementing short helpful codes in the blogs. With the help of these smart codes, you can surely make your posts more interactive and popular. They are sure and short way of coding to achieve better results in blogging with WordPress. Now, using WordPress with these short codes will be an amazing and innovative thing to do, we will surely come back with some new and inventive short codes for you.

 

Jennifer Adam

The area of interest of Jennifer Adam is to cater technologically advanced and powerful tool which works remarkably with multiple browsers and devices. Being a talented professional of inkyROBO, she is capable of implementing the innovative ideas and also loves to write inspiration blogs.