Setting up custom facebook and twitter buttons using php

0
285

The canonical tag has been a god send for us helping to get pages indexed and clean up site structures. In many sites we use the same php variable for our share buttons.

This is a great way to setup custom twitter and facebook share buttons for your pages. We always use an external template file and then include it from the pages but you can hard code this into a single web page if required.

small facebook like and twitter retweet buttons

The images are currently set to images/facebookpic.png and images/twitterpic.pngĀ  You could set it to http://www.facebook.com/favicon.ico if you’re feeling lazy or google image search facebook button for examples. You could get pretty creative with this if you are aiming to give your site a social/seo boost.

<?php
// declare the variables from a seperate page and include(‘mytemplate.php’) or put it all in one page.
$title = ‘My title’;
$canonical = ‘http://www.JetInternetMarketing.co.uk/index.php’;

//output the tags required in <head> obviously meta descriptions etc would be added too.
echo ‘<title>’.$title.'</title>
<link rel=”canonical” href=”‘.$canonical.'” />’;

// Buttons below for <body> section. Note there is no follow me function added to the twitter code, this can be added if required.

$fblink = “http://www.facebook.com/sharer.php?u=”.$canonical.”&amp;t=”.urlencode($title).”&amp;src=sp”;
echo(‘<a title=”Share on Facebook” href=”‘.$fblink.'” target=”_blank”><img src=”images/facebookpic.png” alt=”facebook like” border=”0″ /></a>’);
$twitlink = “http://twitter.com/share?_=1292093673417&amp;count=horizontal&amp;original_referer=”.$canonical.”&amp;text=”.urlencode($title).”&amp;url=”.$canonical;
echo(‘ <a title=”Share on Twitter” href=”‘.$twitlink.'” target=”_blank”><img src=”images/twitterpic.png” alt=”twitter retweet” border=”0″ /></a> ‘);

‘;

?>

LEAVE A REPLY

Please enter your comment!
Please enter your name here