Web Hosting
Web Hosting

Thursday, November 17, 2011

Using shortcodes everywhere in wordpress

At the moment, shortcodes in WordPress are processed only in post/page content. You can use them in lots of other places, though, if you enable them for each field you want. Here's how to use shortcodes in widgets, excerpts, comments, theme files, user descriptions, and category/tag/taxonomy descriptions.

Text Widgets

It's easy to make shortcodes work in text widgets. Just add the following to yourfunctions.php file:

add_filter( 'widget_text', 'shortcode_unautop');
add_filter( 'widget_text', 'do_shortcode');

The second line is the one that makes the shortcodes work, but you'll want to include both. If you check "add paragraphs automatically" on the widget, WordPress will apply the autop filter — the one that turns your line breaks into paragraph and break tags. If a shortcode is on its own line, it would normally get wrapped in a paragraph tag. The first line prevents that from happening.

Template Files

You can use shortcodes right in your theme! Use the do_shortcode() function, where the argument is a string that contains a shortcode.

For example, to print the output of the shortcode [foo] in a theme, add this to the file:

<?php do_shortcode('[foo]'); ?>

The do_shortcode() function accepts any text as its input. If the string contains a shortcode, that code will get processed. So, for example, you could manually process your post content for shortcodes like this:


<?php
$content = get_the_content();
echo do_shortcode($content);
?>

Comments

Do you trust your commenters enough to allow them to use shortcodes? This goes intofunctions.php:

add_filter( 'comment_text', 'shortcode_unautop');
add_filter( 'comment_text', 'do_shortcode' );

Excerpts

To enable shortcodes in excerpts, add these lines to your functions.php file:

add_filter( 'the_excerpt', 'shortcode_unautop');
add_filter( 'the_excerpt', 'do_shortcode');

User Descriptions

There is no filter (as far as I know) for the user description, so in order to display the description with shortcodes, you'll need to fetch the description string, then pass it to the do_shortcode() function. This would go into your theme file:

<?php
// $user_id = 3;
$userdata = get_userdata($user_id);
echo do_shortcode($userdata->description);
?>

Category, Tag, and Taxonomy Descriptions

These descriptions can be filtered, so the code for your functions.php file is simple:

add_filter( 'term_description', 'shortcode_unautop');
add_filter( 'term_description', 'do_shortcode' );

Monday, November 14, 2011

Static FBML : My images do not update even after clearing browser cache

The Fix:

Try renaming the image on the server. Then refresh your Facebook page so it can pick up on the changes. Now you can rename the image again, back to the original. if this method doesnt work then you can rename the image on the server and change the link to the image on the FBML code.

Wednesday, November 9, 2011

Help Your Website Achieve Google Sitelinks

What are sitelinks?

The sitelinks are meant to help your website visitors who search your site name to navigate more easily directly from Google search. While the links are completely automated by Google, you can control them within Google's Webmaster Tools by blocking those that you would not like listed.

What's the benefit?

While Google proclaims that it helps users navigate your site, it also has additional benefits that include:

Google search page coverage – simply it takes up more space on the page which draws attention to your site. Mix it up with Google Adwords and give your website an even better chances of being clicked when searched.
Gets more traffic to internal pages and older posts – encourages visitors to dig deeper into your site and learn more about your company/brand.
Indirectly shows success – Typically only the top websites by Google's standards get sitelinks, so if you luck out, might as well toot your own horn a bit
In addition to also recently noticing that TDC holds a PageRank of 4 in six months, I was unclear how these sitelinks came about. What had I done to achieve these little links of joy?

What can you do?

While Google does not directly state how to achieve sitelinks there has been much discussion around the web in regards to what you can do to increase your chances and amount of time it takes to be awarded with them. Here are a few I've pulled from various studies and observations:

  1. Your site ranks first for the keyword(s) that generate the sitelinks listing
  2. Simple and structured navigation
  3. A fairly high and consistent flow of traffic
  4. High click through rates from the search results page
  5. Useful outbound links
  6. Inbound links from high quality sites
  7. Site age – in age we trust!
  8. Write useful content on your blog
  9. Submit a sitemap in your Google Webmasters Tool panel. If you are using WordPress check out this sitemap plugin.
  10. Use good SEO practices. WordPress users should install the all-in-one SEO pack
  11. Just because you are a "big name" does not necessarily mean your awarded sitelinks. Try Googling 'Doritos'.
Remember: The above do not guarantee that your site will get sitelinks. They are only tried and tested and may be involved in the appearance of sitelinks. What have you done to help being rewarded with Google Sitelinks? Share your tips and thoughts in the comments below.

Saturday, November 5, 2011

How To Use, Style and Implement WordPress Shortcodes

WordPress shortcode API is a powerful function which was introduced from version 2.5, it’s just a simple set of functions for creating macro codes in post content. If you’ve developed a Vbulletin forum before, you would have been familiar with the shortcode (something called BBCode) but the WordPress users maybe not. In this article, I would like to show you how to create and use shortcodes, in addition, I will show you some creative examples of using shortcode in WordPress blog.

What Are Shortcodes?

The shortcodes I’m going to introduce are very simple and easy to use, they look like this:

[text][/text], [clip][/clip], [flv][/flv], [flash][/flash].....

The shortcodes may have attributes or without attributes, so we will go from the easy first.

WordPress Shortcodes without attributes

Example of the shortcodes without attributes:

[text][/text]

How to create? It’s most simple, let’s add the code below to your functions.php file (stored in your current theme directory):

function text() {
return 'Good morning'; } add_shortcode('gm', 'text');

As you see in the code above, the first thing I do is create a function like any other WordPress functions, the function will return the text “Good morning” when called then I add the API call to register the shortcode handler:

add_shortcode('gm', 'text');

The first parameter is a name of the shortcode and the second parameter is the name of the function will be called, in my situation is “text”.

How to use? When posting a new article, whenever you want to display the “Good morning” text, switch the editor to HTML mode and type the following shortcode:

[gm]

WordPress Shortcodes with attributes

WordPress Shortcodes with attributes are more complicated, for example:

[text attribute=""][/text]

The code you should add to your functions.php is:

function text($atts) {
 extract(shortcode_atts(array(
  'attribute' =&gt; 'Good morning' // The default value if you do not pass the attribute to the shortcode
 ), $atts));

 return $attribute;
}
add_shortcode('gm', 'text');

How to use? With attributed shortcode you should pass the value of the attributes to the shortcode when using, if not, the function will use the default value:

[gm attribute="Good night"]

… will output “Good night”, but:

[gm]

… will output “Good morning”

WordPress Shortcodes with attributes and content

After reading and trying two trivial examples above, it’s the time to go to the WP shortcodes which you will deal with a lot of time, let’s see this example:

function a($atts, $content = null) {
 extract(shortcode_atts(array(
        "class" =&gt; '',
        "rel" =&gt; '',
  "url" =&gt; ''
 ), $atts));
 return '<a class="'.$class.'" rel="'.$rel.'" href="'.$url.'">'.$content.'</a>';
}
add_shortcode('link', 'a');

Notes:

  • $atts: an array of attributes.
  • $content: the enclosed content.

So if the shortcode I place on the post editor is:

[link url="http://www.google.com" rel="nofollow" class="hyperlink"]Google[/link]

… the result will be:

<a class="hyperlink" rel="nofollow" href="http://www.google.com">Google</a>

Other ways of using this shortcode:

[link] or [link/] will return: <a></a>
[link]Google[/link] will return <a>Google</a>

Shortcodes were parsed after post formatting was applied so If you do want your shortcode output to be formatted, you should call wpautop() or wptexturize() directly when you return the output from your shortcode handler.WordPress.org

WordPress shortcode is not too hard to understand, and it help you to create a dynamic content for your web blog, you could make anything you want with it, the only limitation is just your imagine, next up I would like to show you how to take advantage of it.

Create Special List Styles

checklist

You could create a special list styles easily with shortcodes, first add the code below to your functions.php file:

function checklist($atts, $content = null) {
 return '
<div class="checklist">'.$content.'</div>
';
}
add_shortcode('checklist', 'checklist')

This shortcode will wrap the <div> around the specific content and we will markup this <div> element by adding to your css file:

.checklist ul {
margin-left:50px;
list-style:none!important
}
.checklist ul li{
padding:5px 5px 5px 30px;
background:#fff url(images/check.png) no-repeat center left
}

Using:

[checklist]
<ul>
 <li>Lorem ipsum dolor sit amet</li>
 <li>Lorem ipsum dolor sit amet</li>
 <li>Lorem ipsum dolor sit amet</li>
 <li>Lorem ipsum dolor sit amet</li>
</ul>
[/checklist]

Thanks to http://www.dezinerfolio.com for the free icon set.

Create Box Styles

box-style

The code:

function box($atts, $content = null) {
 return '
<div class="box">;'.$content.'</div>
';
}
add_shortcode('box', 'box');[php]
The css:
[css].box {
background:#bfe4f9;
border:1px solid #68a2cf;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
padding:10px
}[/css]
Using:
[html][box]Mauris ut lectus erat. In condimentum, turpis ac ultricies laoreet, felis ante aliquet nulla, vitae volutpat nunc sapien eget quam. Proin auctor auctor mollis. Curabitur congue sem ante, luctus euismod lorem. In iaculis ultrices lorem, ut viverra ipsum fringilla.[/box][/html]
<h3>Create Dropcaps</h3>
<img src="http://www.tuttoaster.com/wp-content/uploads/2010/06/dropcap1.png" alt="dropcap" width="517" height="96" />

The code:
[php]function dropcap($atts, $content = null) {
 return '
<div class="dropcap">'.$content.'</div>
;';
}
add_shortcode('dropcap', 'dropcap');
]

The css:

.dropcap {
display:block;
float:left;
font-size:50px;
line-height:40px;
margin:0 8px 0 0;
}

Using:

Mauris ut lectus erat. In ...

Create A Download Button

download

The code:

function download($atts, $content = null) {
 extract(shortcode_atts(array(
  "url" =&gt; ''
 ), $atts));
 return '<a class="download" href="'.$url.'">'.$content.'</a>';
}
add_shortcode('download', 'download');

The css:

.download {
display: inline-block;color:#fff;
font-weight:bold;
font-size:1.2em;
background : -webkit-gradient(linear, left top, left bottom, from(#88c841), to(#73b338));
background : -moz-linear-gradient(center top, #88c841, #73b338);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
padding: 5px 20px;
text-align: center;
-shadow: 0px 1px 0px #6c0909;
}

.download:hover {
background : -webkit-gradient(linear, left top, left bottom, from(#73b338), to(#88c841));
background : -moz-linear-gradient(center top, #73b338, #88c841);
}

Using:

[download url="http://www.google.com"]Download Google Chrome[/download]

Jquery Slide Up / Slide Down Shortcode

scroll

The code:

function slide($atts, $content = null) {
 extract(shortcode_atts(array(
  "title" =&gt;; ''
 ), $atts));
 return '<a class="slide">'.$title.'</a>

'.$content.'

';
}
add_shortcode('slide', 'slide');

The css:

.slide {cursor:pointer}
.slide-next {display:none}

The Javascript: (You can add the javascript code to your footer.php file)

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"><!--mce:0--></script>
<script type="text/javascript"><!--mce:1--></script>

Using:

[slide title="Lorem ipsum dolor sit amet"]Mauris ut lectus erat. In condimentum, turpis ac ...[/slide]

Post Content In Column

column

The code:

function half($atts, $content = null) {
 return '
<div class="half">'.$content.'</div>
';
}
function half_last($atts, $content = null) {
 return '
<div class="half-last">'.$content.'</div>
<br style="clear: both;" />';
}
add_shortcode('half', 'half');
add_shortcode('half_last', 'half_last');

The css:

.half, .half-last {float:left;width:47%;margin:10px 0;margin-right:6%;}
.half-last {margin-right:0}

Using:

[half]Mauris ut lectus erat. In condimentum, turpis ...[/half]

[half_last]Mauris ut lectus erat. In condimentum, turpis ...[/half_last]

Of course, you could modify the code to create 3,4 or 5 columns post layout as your needs :) .

Create A Multiple URL Shortener Shortcode

This is an exclusive WordPress Shortcode I created for Tuttoaster.com, all you need to do is give shortcode the URL then it will shorten via the most 4 popular sevices: : tinyURL, Google shortener, is.gd and Su.pr (Stumbleupon), paste the code below to your functions.php file:

function getContent($url) {
    $content = '';
    if (function_exists('curl_init')) {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_HEADER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        $content = curl_exec($ch);
        curl_close($ch);
    }
    elseif (ini_get('allow_url_fopen')) {
        $content = file_get_contents($url);
    }
    return $content;
}

function short($atts) {
 extract(shortcode_atts(array(
  "url" =&gt; ''
 ), $atts));
 $googledata = getContent("http://ggl-shortener.appspot.com/?url=$url");
    $googlejson = json_decode($googledata);

 $isgd = getContent("http://is.gd/api.php?longurl=$url");
 $tinyurl = getContent("http://tinyurl.com/api-create.php?url=$url");
 $google = $googlejson-&gt;short_url;
 $supr = getContent("http://su.pr/api?url=$url");

 $output = '
<ul>';
 $output .= '
 <li>Is.gs: <a href="'.$isgd.'">'.$isgd.'</a></li>
';
 $output .= '
 <li>Google: <a href="'.$google.'">'.$google.'</a></li>
';
 $output .= '
 <li>Tinyurl:<a href="'.$tinyurl.'">'.$tinyurl.'</a>;</li>
';
 $output .= '
 <li>Su.pr: <a href="'.$supr.'">;'.$supr.'</a></li>
';
 $output.='</ul>
';
 return $output;
}
add_shortcode('short', 'short');

How to use? It’s very simple, huh?:

[short url="http://url-need-to-be-shortened.com"]

And the result would be:

url-short

In the shortcode code above, I think you should register for the services account and using the callback with APIKey then your post content does not need to re-shorten the URL every-time loaded.

The next following is 2 shortcodes which I like most and I want to introduce to you:

Get posts from WordPress Database with a Shortcode

The code:

function sc_liste($atts, $content = null) {
        extract(shortcode_atts(array(
                "nombre" =&gt; '5',
                "cat" =&gt; ''
        ), $atts));
        //requete sur la BDD pour recuperr la liste de billet
        global $post;
        $myposts = get_posts('numberposts='.$nombre.'&amp;order=DESC&amp;orderby=post_date&amp;category='.$cat);
        $retour='
<ul>';
        foreach($myposts as $post) :
                setup_postdata($post);
             $retour.='
 <li><a href="'.get_permalink().'">'.the_title("","",false).'</a></li>
';
        endforeach;
        $retour.='</ul>
';
        //on renvoi la liste
        return $retour;
}
add_shortcode("liste", "sc_liste");

Using: (It will display 3 posts from the category ID = 1)

[liste nombre="3" cat="1"]

The code source.

Hide Content From The Public

The code:

function guest_check_shortcode( $atts, $content = null ) {
  if ( ( !is_user_logged_in() &amp;&amp; !is_null( $content ) ) || is_feed() )
  return $content;
 return '';
}
add_shortcode( 'guest', 'guest_check_shortcode' );
function member_check_shortcode( $atts, $content = null ) {
  if ( is_user_logged_in() &amp;&amp; !is_null( $content ) &amp;&amp; !is_feed() )
  return $content;
 return '';
}
add_shortcode( 'member', 'member_check_shortcode' );

Thursday, November 3, 2011

How To Install WhatsApp On iPod Touch and iPad Without Jailbreak

Whats app is an application for iPhoneAndroid and other mobile platform that lets you to send text message between your friends at free of cost. Whats app cannot be installed on iPod Touch and iPad because its not compatible with it. Now you can easily install it on your iPod Touch or iPad without Jail-breaking your device.

All you need is iPhone Configuration utility and iTunes.

Download iTunes For Windows and Mac

Download iPhone Configuration utility for Windows and Mac

In my case I tried with iTunes 10.5 Beta, iOS 5 and iPod Touch 4th Gen

Step To Follow

1. Open your iTunes and looks for the App that is not compactable with your iPod Touch or iPad

2. Install and open the iPhone Configuration utility before that make sure you connected your iDevice on Windows PC or Mac

3. Check on the left panel on iPhone configuration utility.

Click on application, Add file and locate the .ipa file you want to add or simply drag and drop the .ipa file to iPhone configuration utility

You can Locate the .ipa at the following path

For Mac user

/Music/iTunes/iTunes Media/Mobile Application

For Windows user

C:\Users\USER\Music\iTunes\iTunes Media\Mobile Applications

Note : The paths mentioned above are default ones, if you changed the path them check the .ipa file there.

4. Check for Devices on the left panel on iPhone configuration utility and make sure your iDevice is listed.

Click on your device and go to application. A list of applications will will shown and in our case you can see Install button next to wahts app. Click on it and allow few seconds

Give it some time it will be installed on your deice and you will see the uninstall button next to the app installed.

5. Now you can enjoy whatsapp on your iPod Touch or iPad. You can also do the same for other apps to make it force install if its not compatible with your iPod Touch or iPad

Screen Snaps from iPod Touch

Hope you enjoy whats app on you iPod Touch and iPad

We noticed that many users got kAMDRecieveMessageError Here is a solution to fix it..

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Facebook Themes