Matthew J. Kellett

Website Architect and Developer

Google Plusone iFrame

Looking to add Google's new plusone feature to your site but don't have HTML5 enabled pages? Then keep reading grin

The Code

<?php
$url = isset($_GET['url']) ? htmlspecialchars($_GET['url']) : "";
$size = isset($_GET['size']) ? htmlspecialchars($_GET['size']) : "tall";
if ($url != "") {
?>
<!DOCTYPE html>
<html>
<head>
	<style type="text/css">
		html,
		body {
			margin:0;
			padding:0;
			width:auto;
			overflow:hidden;
		}
	</style>
	<script type="text/javascript" src="http://apis.google.com/js/plusone.js" />
</head>
<body>
	<g:plusone size="<?php echo $size; ?>" href="<?php echo $url; ?>"></g:plusone>
</body>
</html>
<?php
}
?>
				

The Explanation

The best way to use the above code is to drop it into a PHP file called plusone.php and drop it into the root of your site.

The next step is to call this script in your main code to display the button where you want it. The code below shows the basics of what you need to include:

<iframe src="/plusone.php?url={PAGE_URL}&size={BUTTON_TYPE}" marginheight="0" marginwidth="0" frameborder="0" scrolling="no" style="border:0;width:58px;height:70px;"></iframe>
				

From the URL you will see two tags, {PAGE_URL} and {BUTTON_TYPE}, hopefully replacing these with actual information is easy enough to figure out but in case not, see below for details wink

  • {PAGE_URL} - This is the URL for the page you want people to like and share
  • {BUTTON_TYPE} - This is size of the button that people will click on from one of the images below.

There are four sizes for Google's + button which can be seen in the image below:

Google + Dimensions

Please feel free to let me know you use this code so I can tell if this is actually useful to anyone

Comments

There are no comments for this article

Like, follow, share us

Code Categories

Use the links below to view each of the different code snippet categories

Latest Code Snippets

Below are the latest code snippets that I have written

Donations

If you like this code snippet or use it then please donate something to me so I can continue updating this as well as creating new ones