James Bachini

Setting up custom facebook and twitter buttons using php

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> ‘);

‘;

?>


Get The Blockchain Sector Newsletter, binge the YouTube channel and connect with me on Twitter

The Blockchain Sector newsletter goes out a few times a month when there is breaking news or interesting developments to discuss. All the content I produce is free, if you’d like to help please share this content on social media.

Thank you.

James Bachini

Disclaimer: Not a financial advisor, not financial advice. The content I create is to document my journey and for educational and entertainment purposes only. It is not under any circumstances investment advice. I am not an investment or trading professional and am learning myself while still making plenty of mistakes along the way. Any code published is experimental and not production ready to be used for financial transactions. Do your own research and do not play with funds you do not want to lose.


Posted

in

, ,

by