Shortcode for the Facebook like button


Shortcode Usage:

[fblike]  




/using parameters - [fblike param='value']/

action='recommend'  

layout='button_count'  

layout='box_count'  

send='true'     /adds the send button/
 
function fblike_func( $atts, $content=null ){
    extract(shortcode_atts(array(
            'send' => 'false',
            'layout' => 'standard',
            'show_faces' => 'true',
            'width' => '450px',
            'action' => 'like',
            'font' => 'arial',
            'colorscheme' => 'light',
            'ref' => '',
            'locale' => 'en_US',
            'appId' => '' // AppId if you have one
    ), $atts));
    //check vars for wrong parameters
    if($send != 'false' && $send != 'true'){$send='false';}
    if($show_faces != 'false' && $show_faces != 'true'){$show_faces='true';}
    if($action != 'like' && $action != 'recommend'){$action='like';}
    if($layout != 'standard' && $layout != 'button_count' && $layout != 'box_count'){$layout='standard';}
    $fblike_code = <<<HTML
        <div id="fb-root"></div>
        <script>(function(d, s, id) {
          var js, fjs = d.getElementsByTagName(s)[0];
          if (d.getElementById(id)) return;
          js = d.createElement(s); js.id = id;
          js.src = "//connect.facebook.net/$locale/all.js#appId=$appId&xfbml=1";
          fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));</script>
    <fb:like ref="$ref" href="$content" width="$width" colorscheme="$colorscheme" layout="$layout" action="$action" show_faces="$show_faces" send="$send" font="$font"></fb:like>
HTML;
    return $fblike_code;
}
add_shortcode('fblike', 'fblike_func');
 
/related example - How to add a shortcode/

Additional Info
Facebook Like API