in

Best Smart Short Codes for WordPress

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.

[button]

In order to customize the call for action button, we can simply add

[button type=”twitter”]

We can even make it even better by enclosing the shortcode as shown below:

[button type=”twitter”]Follow me on Twitter![/button]

 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:

[button]

Here, one can simply use the add_shortcode() function, one can link any PHP feature to the short code. In the easy instance of self closing short code we are just returning a link to our twitter account.

Generating a self-closing short code with restricted parameters

Short codes also support restricted parameters through which we can customize the output. In the below example we are provided with two different kind of buttons where we are needed to specify which button we wish to show.

See the code below:

<?php
function button_shortcode($type) {
extract(shortcode_atts(array(
‘type’ => ‘type’), $type));

// check what type user entered

switch ($type) {
case ‘twitter’:
return ‘<a href=”http://twitter.com/filipstefansson” class=”twitter-button”>Follw me on Twitter!</a>’;
break;
case ‘rss’:
return ‘<a href=”http://example.com/rss” class=”rss-button”>Subscribe to the feed!</a>’
break;
}
}
add_shortcode(‘button’, ‘button_shortcode’);
?>

At this time, you are free to opt for any button that you want to display by defining its type in the short code you are providing.

[button type=”twitter”]

[button type=”rss”]

This step is awesome but if one wants to change the textual content. In that case, one need to keep on adding short codes like [button type=”twitter-2″] and similar to that.

Generate enclosing short codes

With the help of enclosing short code, one can insert the content within the chort code itself. It is similar to BBCode.

See the code below:

<?php
function button_shortcode( $attr, $content = null ) {
return ‘<a href=”http://twitter.com/filipstefansson” class=”twitter-button”>’ . $content . ‘</a>’;
}
add_shortcode(‘button’, ‘button_shortcode’);
?>

In order to utilize this short code, you can insert the content in any way you like.

[button]Follow me on Twitter![/button]

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:

[button account=”filipstefansson” style=”simple”]Follow me on Twitter![/button]
// 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(“[button]”);

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.

What do you think?

Written by Jennifer Adam

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Loading…

0

Comments

0 comments

15 + Most Eye-Catching Donation Pages: An Assortment of Fabulous Web design

Complete Guide on Lomography for Designers Creativity and Experimental Analogue Film Photography