Skip to content

Instantly share code, notes, and snippets.

@tegansnyder
Last active December 23, 2015 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tegansnyder/6586013 to your computer and use it in GitHub Desktop.
Save tegansnyder/6586013 to your computer and use it in GitHub Desktop.
<?php
<meta http-equiv="Content-Type" content="<?php echo $this->getContentType() ?>" />
<title><?php echo $this->getTitle() ?></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<?php
if (Mage::registry('current_product')) {
$current_product = Mage::registry('current_product');
$desc = preg_replace('/\s+?(\S+)?$/', '', substr(strip_tags(str_replace(array("\r\n", "\r", "\n"), "", $this->getDescription())), 0, 150));
$desc = str_replace("&rsquo;","'", $desc);
$desc = str_replace("&nbsp;"," ", $desc);
?>
<meta name="description" content="<?php echo $desc; ?>" />
<?php } else { ?>
<meta name="keywords" content="<?php echo htmlspecialchars($this->getKeywords()) ?>" />
<?php } ?>
<meta name="robots" content="<?php echo htmlspecialchars($this->getRobots()) ?>" />
<link rel="icon" href="<?php echo $this->getFaviconFile(); ?>" type="image/x-icon" />
<link rel="shortcut icon" href="<?php echo $this->getFaviconFile(); ?>" type="image/x-icon" />
<meta property="og:type" content="website"/>
<?php
if (Mage::registry('current_product')) {
$product_image = Mage::getModel('catalog/product_media_config')->getMediaUrl($current_product->getSmallImage());
?>
<meta property="og:description" content="<?php echo $desc;?>"/>
<meta property="og:image" content="<?php echo $product_image;?>" />
<meta property="og:title" content="<?php echo $current_product->getName();?>" />
<meta property="og:url" content="<?php echo Mage::app()->getStore()->getCurrentUrl(false); ?>"/>
<meta name="twitter:card" content="product">
<meta name="twitter:title" content="<?php echo $current_product->getName();?>" />
<meta name="twitter:description" content="<?php echo $desc;?>" />
<meta name="twitter:image" content="<?php echo $product_image;?>" />
<meta name="twitter:data1" content="$<?php echo number_format($current_product->getPrice(),2);?>">
<meta name="twitter:label1" content="PRICE">
<?php if($current_product->getStockItem()->getIsInStock()) { ?>
<meta name="twitter:data2" content="In stock!">
<?php } else { ?>
<meta name="twitter:data2" content="Out of stock">
<?php } ?>
<meta name="twitter:label2" content="AVAILABILITY">
<meta name="twitter:site" value="@YourTwitterHandle">
<?php
} else { // regular CMS page... not a product
?>
<meta property="og:description" content="Your website description for facebook"/>
<meta property="og:title" content="My Company Name Store"/>
<meta property="og:image" content="http://www.domain.com/facebook-image.png"/>
<meta property="og:url" content="http://www.domain.com/"/>
<?php } ?>
<meta property="og:locale" content="en_US" />
<meta property="og:site_name" content="My Company Name Store"/>
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment