<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>gj |</title>
	<atom:link href="https://blog.gaiterjones.com/category/seo/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.gaiterjones.com/category/seo/</link>
	<description>gaiterjones</description>
	<lastBuildDate>Thu, 08 Dec 2011 09:26:57 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.4.3</generator>
	<item>
		<title>Rich Snippet Data for Magento Product Pages Improves Google Search Results</title>
		<link>https://blog.gaiterjones.com/rich-snippet-data-for-magento-product-pages-improves-google-search-results/</link>
					<comments>https://blog.gaiterjones.com/rich-snippet-data-for-magento-product-pages-improves-google-search-results/#comments</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Fri, 18 Nov 2011 13:34:44 +0000</pubDate>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[Marketing]]></category>
		<category><![CDATA[META Tags]]></category>
		<category><![CDATA[Rich Snippet Data]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[microformat tags]]></category>
		<category><![CDATA[rich snippet data]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=595</guid>

					<description><![CDATA[&#160; &#160; &#8220;Rich Snippets&#8221; are a standardised markup format used by Google to improve search results by including more specific or &#8220;rich&#8221; information relating to a web page, i.e. for...<a class="more-link" href="https://blog.gaiterjones.com/rich-snippet-data-for-magento-product-pages-improves-google-search-results/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&#8220;<a href="http://www.google.com/support/webmasters/bin/topic.py?topic=21997" target="_blank">Rich Snippets</a>&#8221; are a standardised markup format used by Google to improve search results by including more specific or &#8220;rich&#8221; information relating to a web page, i.e. for product pages, price and ratings info. Google says &#8220;(we try) to present users with the most useful and informative search results. The more information a search result snippet can provide, the easier it is for users to decide whether that page is relevant to their search.&#8221;</p>
<p>By editing Magento product page templates we can include the Rich Snippet markup data readable by Google and improve the organic Google search results for our product pages.</p>
<p>There are various standards available to markup Rich Snippet Data on web pages &#8211; microdata, microformats, RDFa etc. We are going to use the microformat markup, although it does not provide as many options as other formats it does fit more easily into Magentos existing default product page design.</p>
<h2><span class="Apple-style-span" style="font-weight: normal; line-height: 20px; text-transform: none;">This Rich Snippet data will not affect the look of our product page, microformats use the </span><code style="line-height: 20px; text-transform: none;">class</code><span class="Apple-style-span" style="font-weight: normal; line-height: 20px; text-transform: none;"> attribute in HTML tags (often </span><code style="line-height: 20px; text-transform: none;">&lt;span&gt;</code><span class="Apple-style-span" style="font-weight: normal; line-height: 20px; text-transform: none;"> or </span><code style="line-height: 20px; text-transform: none;">&lt;div&gt;</code><span class="Apple-style-span" style="font-weight: normal; line-height: 20px; text-transform: none;">) to assign brief and descriptive names to entities and their properties.</span></h2>
<p>We are going to use simple microformat conventions or entities to markup our product page html so that Google spiders can read Rich data from our product information such as the price, availability or review rating of a product from all our pages.</p>
<p>We will implement two main microformat entities, <strong>hproduct</strong> and <strong>hreview-aggregate</strong> coded within the correct sections of our product page html so that the microformat markup looks something like:</p>
<figure id="attachment_596" aria-describedby="caption-attachment-596" style="width: 244px" class="wp-caption alignnone"><img fetchpriority="high" decoding="async" class="nohang        " title="Rich Snippet product microformat tree" src="https://blog.gaiterjones.com/wp-content/uploads/2011/11/magento-rich-snippet-microformat.jpg" alt="" width="244" height="207" /><figcaption id="caption-attachment-596" class="wp-caption-text">Rich Snippet product microformat tree</figcaption></figure>
<p>&nbsp;</p>
<h1>How to Markup the Default Magento Theme with Rich Snippet Information</h1>
<p>&nbsp;</p>
<p>Lets start with the hproduct microformat tag. This needs to encapsulate the main product information, including product description, image, price etc. If we look at the structure of the default magento product page we can see that the html document division with the product-essential class contains all the product information that we need, so we will add the main hproduct microformat tag here by adding hproduct to the DIV class.</p>
<figure id="attachment_597" aria-describedby="caption-attachment-597" style="width: 440px" class="wp-caption alignnone"><a href="https://blog.gaiterjones.com/wp-content/uploads/2011/11/magento-product-wrapper-div.jpg"><img decoding="async" class="nohang        " title="HTML document division containing Magento product information" src="https://blog.gaiterjones.com/wp-content/uploads/2011/11/magento-product-wrapper-div-440x263.jpg" alt="" width="440" height="263" /></a><figcaption id="caption-attachment-597" class="wp-caption-text">HTML document division containing Magento product information</figcaption></figure>
<p>&nbsp;</p>
<h2>hproduct</h2>
<p>Open up your Magento theme template folder, browse to  /template/catalog/product and open up view.phtml for editing. Here you will find the html document division with the class <strong>product-essential</strong>, we simply append the new <strong>hproduct</strong> microformat class to it to add the hproduct rich snippet tag.</p>
<pre class="brush:xml">&lt;div class="product-essential hproduct"&gt;</pre>
<h2>item fn</h2>
<p>Within our microformat markup tree we now want to markup the product item, price and image sections of our Magento product html.</p>
<p>Still looking at view.phtml within the product-essential div we will find the product-name division. Here we will add the<strong> item fn</strong> microformat tags to markup the product name.</p>
<pre class="brush:xml">&lt;div class="product-name item fn"&gt;</pre>
<h2>description</h2>
<p>Within view.phtml we can also add the markup for the microformat description tag. An ideal place for this is the quick overview html division where we can simply append the description tag to the existing DIV class.</p>
<pre class="brush:xml">&lt;div class="std description"&gt;&lt;?php echo $_helper-&gt;productAttribute($_product, nl2br($_product-&gt;getShortDescription()), 'short_description') ?&gt;&lt;/div&gt;</pre>
<h2>price</h2>
<p>To markup the product price open up price.html in the same folder. This template file is responsible for returning product pricing in all areas of the Magento frontend. You will notice that all the pricing document divisions already have the class name <strong>price. </strong>We don&#8217;t need to change anything here. However if you want to include the price-range microformat tag you can include it here by adding it to the divisions with the class name <strong>price-box</strong>.</p>
<h2>image</h2>
<p>To tag the product image navigate to the template/catalog/product/view folder and open up media.phtml for editing. Here you will see the product image html. The product image URL is specified within an IMG tag that has the ID &#8220;image&#8221;. Simply add a new class to the IMG tag with the name <strong>photo fn</strong>.</p>
<pre class="brush:xml">$_img = '&lt;img id="image" class="photo fn" src="'.$this-&gt;helper...</pre>
<h2>hreview-aggregate</h2>
<p>The most effective data we can microformat tag is the product review and rating data which will be displayed in Google search results showing our Magento product rating information. This data is encapsulated within the hreview-aggregate tag.</p>
<p>Navigate to the template/review/helper folder and you will see two files responsible for rendering review and rating html. summary.phtml and summary_short.phtml. Open up summary.phtml for editing.</p>
<p>First we need to add the hreview-aggregate tag to the html division that contains the rating data for the product. Here you will see the DIV with the class name ratings. Append the hreview-aggregate tag to this DIV class name.</p>
<pre class="brush:xml">&lt;div class="ratings hreview-aggregate"&gt;</pre>
<p>Next you will see that Magento already uses a division with a class name of rating. This will confuse Google as the microformat name we want to use is also &#8220;rating&#8221;. However there is a method to work around this using a SPAN class. Edit the existing rating division to include the new SPAN element as show below.</p>
<pre class="brush:xml">            &lt;div class="rating-box"&gt;
                &lt;div class="rating" style="width:&lt;?php echo $this-&gt;getRatingSummary() ?&gt;%"&gt;
					&lt;span class="value-title" title="&lt;?php echo number_format($this-&gt;getRatingSummary() / 20,1); ?&gt;"&gt;&lt;/span&gt;
				&lt;/div&gt;
            &lt;/div&gt;</pre>
<h2>count</h2>
<p>Now we markup the number of reviews the product has received with the <strong>count</strong> tag. Still within summary.phtml we add a SPAN element with the class name count to the existing code.</p>
<pre class="brush:xml">        &lt;p class="rating-links"&gt;
			&lt;a href="&lt;?php echo $this-&gt;getReviewsUrl() ?&gt;"&gt;&lt;span class="count"&gt;&lt;?php echo $this-&gt;getReviewsCount()?&gt;&lt;/span&gt;&lt;?php echo $this-&gt;__(' Review(s)') ?&gt;&lt;/a&gt;
            &lt;span class="separator"&gt;|&lt;/span&gt;
            &lt;a href="&lt;?php echo $this-&gt;getReviewsUrl() ?&gt;#review-form"&gt;&lt;?php echo $this-&gt;__('Add Your Review') ?&gt;&lt;/a&gt;
        &lt;/p&gt;</pre>
<h1>author</h1>
<p>Finally lets consider the author tag. To identify the author of a blog or article, Google checks for a connection between the content page (such as an article), an author page, and a <a href="http://www.google.com/profiles">Google Profile</a>. I am unsure if any real benefit will come from applying the author tag to your product content but for completeness one way to do it is to add the author tag to a link in the footer of your Magento pages. i.e.</p>
<pre class="brush:xml">&lt;p class="author"&gt;&lt;a rel="author" href="http://my.google.profile "&gt;g a i t e r j o n e s&lt;/a&gt; / &lt;?php echo $this-&gt;__('(ver. %s)', Mage::getVersion()) ?&gt;&lt;/p&gt;</pre>
<h1>Testing</h1>
<p>After saving all our edited files, we can check whether our product pages are returning rich snippet data using the <a href="http://www.google.com/webmasters/tools/richsnippets" target="_blank">Google Rich Snippet Testing Tool</a>. Goto the testing page and enter the URL of a product page from your Magento site.</p>
<figure id="attachment_598" aria-describedby="caption-attachment-598" style="width: 440px" class="wp-caption alignnone"><a href="https://blog.gaiterjones.com/wp-content/uploads/2011/11/rich-snippet-testing-tool-preview.jpg"><img decoding="async" class="nohang        " title="Google Rich Snippet Testing Tool Magento Product Preview" src="https://blog.gaiterjones.com/wp-content/uploads/2011/11/rich-snippet-testing-tool-preview-440x103.jpg" alt="" width="440" height="103" /></a><figcaption id="caption-attachment-598" class="wp-caption-text">Google Rich Snippet Testing Tool Magento Product Preview</figcaption></figure>
<p>&nbsp;</p>
<p>The rich snippets testing tool will show you all the rich snippet data for your product page including information that comes from non microformat tags such as Meta tags or Facebook Open Graph tags. Make sure you are making best use of these tags too to ensure that Google is gleaning as much useful SEO information from your pages as possible.</p>
<h1> Conclusion</h1>
<p>The main question now is will Google use our Rich Snippet data in search results and how long will it take before the Rich Snippet data shows up* &#8211; SEE UPDATE BELOW!</p>
<p>I am still unsure if Rich Snippet data is being used across all Google search engines and countries at this moment. The data will certainly not show up until your site is spidered, and there is no guarantee it seems that even when Google has your RIch Snippet data if they will use it or not in search results &#8211; Google says &#8220;Note that there is no guarantee that a Rich Snippet will be shown for this page on actual search results.&#8221; The FAQ page which was written in 2010 seems to suggest the use of Rich Snippet Data is limited and suggests that interested users complete an &#8220;<a href="http://www.google.com/support/webmasters/bin/request.py?contact_type=rich_snippets_feedback" target="_blank">interested in Rich Snippets</a>&#8221; form. See the Rich Snippets Google <a href="http://knol.google.com/k/google-rich-snippets-tips-and-tricks#Frequently_Asked_Questions" target="_blank">FAQ </a>for more infomation.</p>
<p>If and when Rich Snippet data is widely used by Google in search results it certainly can&#8217;t do any harm to ensure your Magento product pages are ready!</p>
<p>* <span class="Apple-style-span" style="font-weight: bold; line-height: 15px; text-transform: uppercase;">UPDATE</span></p>
<p>I wrote this blog entry on 18th November 2011 and around the same time implemented rich snippet data in one of my webshops I just performed a Google search for one of our products today (8th December) and the rich snippet product review data is now being shown. So it took approximately three weeks for Google to pick up the new rich snippet data in our Magento products and reflect them in relevant search results.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/rich-snippet-data-for-magento-product-pages-improves-google-search-results/feed/</wfw:commentRss>
			<slash:comments>18</slash:comments>
		
		
			</item>
		<item>
		<title>Magento Product Social Media Marketing Part 1 &#8211; the Facebook Like Button</title>
		<link>https://blog.gaiterjones.com/magento-social-media-marketing-facebook-like-button/</link>
					<comments>https://blog.gaiterjones.com/magento-social-media-marketing-facebook-like-button/#comments</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Wed, 23 Feb 2011 13:44:55 +0000</pubDate>
				<category><![CDATA[Facebook]]></category>
		<category><![CDATA[Magento]]></category>
		<category><![CDATA[Marketing]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[IFrame]]></category>
		<category><![CDATA[Like Button]]></category>
		<category><![CDATA[Open Graph]]></category>
		<category><![CDATA[Social Media Marketing]]></category>
		<category><![CDATA[XFBML]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=121</guid>

					<description><![CDATA[What is Social Media Marketing? According to Wikipedia its &#8220;a means to gain customer and competitive insight, recruitment and retention of new customers/business partners, and a method of managing their...<a class="more-link" href="https://blog.gaiterjones.com/magento-social-media-marketing-facebook-like-button/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p>What is Social Media Marketing? According to <a href="http://en.wikipedia.org/wiki/Social_media_marketing" target="_blank">Wikipedia </a>its &#8220;<em>a means to gain customer and competitive insight, recruitment and retention of new customers/business partners, and a method of managing their reputation online</em>.&#8221; It is a powerful way to create social exposure for your products and boost traffic to your site.</p>
<p><a href="http://www.twitter.com" target="_blank">Twitter</a>, <a href="http://www.facebook.com" target="_blank">Facebook </a>and <a href="http://www.youtube.com">Youtube </a>are the most popular social networking destinations, I&#8217;ve already looked at how to automatically generate <a href="https://blog.gaiterjones.com/automatic-magento-product-marketing-tweets-for-twitter/" target="_blank">product marketing Tweets for Twitter</a>, so let&#8217;s now turn our attention to Facebook and look at ways to integrate  product information from a Magento eCommerce store into the Facebook Social Graph by implementing the Facebook Like Button on all Magento product, category or cms pages.</p>
<p><img loading="lazy" decoding="async" class="alignleft size-full wp-image-206" style="margin: 5px;" title="Facebook Like Button" src="https://blog.gaiterjones.com/wp-content/uploads/2011/02/facebook_like_button.jpg.336x0.jpg" alt="" width="111" height="76" srcset="https://blog.gaiterjones.com/wp-content/uploads/2011/02/facebook_like_button.jpg.336x0.jpg 336w, https://blog.gaiterjones.com/wp-content/uploads/2011/02/facebook_like_button.jpg.336x0-300x203.jpg 300w" sizes="(max-width: 111px) 100vw, 111px" />You will have seen the Facebook Like Button everywhere, but what exactly is it? <a href="http://developers.facebook.com/docs/reference/plugins/like/">Facebook </a>calls the Like Button a <em>Social Plugin</em> that &#8220;&#8230;lets a user share your content with friends on Facebook. When the user clicks the Like button on your site, a story appears in the user&#8217;s friends&#8217; News Feed with a link back to your website.&#8221;  The Like Button is both simple and powerful. The concept is simple, Facebook users click the Like button to &#8220;like&#8221; something and indicate its cool to their friends. Their friends see the link they have liked in their Facebook news feed and are therfore also encouraged to click it. When the Like Button is integrated into your eCommerce store, the Facebook user (customer) indicates their confidence, satisfaction etc in your products by clicking the Like Button creating a great marketing opportunity for you by sharing your products with all of their friends. But there is more to it than that, because clicking the like button also integrates your product page into the Facebook &#8220;Open Graph&#8221; database.  Facebook says &#8220;If you include Open Graph tags on your Web page, your page becomes <em>equivalent to a Facebook page</em>. This means when a user clicks a Like button on your page, a connection is made between your page and the user. Your page will appear in the &#8220;Likes and Interests&#8221; section of the user&#8217;s profile, and you have the ability to <em>publish updates </em>to the user. Your page will show up in same places that Facebook pages show up around the site (e.g. search), and you can target ads to people who like your content.&#8221; Facebook is attempting to assimilate the Internet into its own Database ultimately turning all Internet pages into Facebook Open Graph objects. With a user base of around 400 million, whether you are a Facebook fan or not this marketing opportunity should not be neglected!</p>
<p>On Sunday 27th February 2011 Facebook altered the functionality of the Like button to replace the functionality of the Share button. The &#8220;Share&#8221; button will see no further development according to Facebook Spokeswoman Malorie Lucich. The company will continue to support the Share button but Like is the “recommended solution moving forward.” The main difference users will now see is that likes to external content are shown in profiles and news streams as &#8220;user likes a link TO EXTERNAL CONTENT&#8221; instead of &#8220;user likes EXTERNAL CONTENT&#8221;. The latter still applying for content hosted on Facebook.</p>
<p>Implementing the Like Button with Magento is relatively simple and there are <a href="http://www.magentocommerce.com/magento-connect/filter/all?query=facebook" target="_blank">extensions </a>available from Magento Connect (even a free one!) the most important aspect of implementing the Like Button is getting the Open Graph data right to ensure that your products are &#8220;assimilated&#8221; correctly into Facebook with a unique and constant URL,  product title, image and meaningful SEO rich description. Check out the extensions with that in mind, if you want to implement the Like Button yourself within Magento 1.3, 1.4 or 1.5 here&#8217;s how I did it. I strongly <em>recommend </em>you develop your Facebook Like button on a development server and not your live site!</p>
<h2>Go Canonical</h2>
<p>The Like Button requires a unique URL to identify your product page in the Facebook Open Graph database.  Magento is notorious for creating duplicate content, generating mulitple URLs for the same product content so it is also good SEO practice to implement the <a href="http://yoast.com/canonical-url-links/" target="_blank">canonical URL</a> tag within the header of your site to tell search engines which URL they <em>should</em> use for your products to avoid duplicating search engine content. The canonical URL is perfect for the Facebook Open Graph URL tag. In Magento 1.4.x and above Canonical URLs are included in the core code, for Magento 1.3.x use the <a href="http://yoast.com/" target="_self">Yoast </a>canonical URL extension its free and installs quickly and easily. Here&#8217;s how to install the extension under 1.3.</p>
<p><strong>Magento Community Edition 1.3.x</strong></p>
<p>You can find the Yoast canonical URL extension on <a href="http://www.magentocommerce.com/magento-connect/Yoast/extension/906/canonical-url-s-for-magento">Magento Connect</a> <span style="text-decoration: underline;">note</span> there are <a href="http://yoast.com/tools/magento/canonical/" target="_blank">issues </a>with this extension if you already use the Fooman Speedster module that you need to workaround.</p>
<p>I installed it under Magento 1.3.x using the command line <em>PEAR </em>installer :</p>
<pre class="brush:plain">dev/magento1-3-3-dev# ./pear mage-setup
Running initial setup...
config-set succeeded
Channel "connect.magentocommerce.com/core" is already initialized
Channel "connect.magentocommerce.com/community" is already initialized

dev/magento1-3-3-dev# ./pear install magento-community/canonical_url-1.3
downloading canonical_url-1.3.tgz ...
Starting to download canonical_url-1.3.tgz (3,866 bytes)
....done: 3,866 bytes
install ok: channel://connect.magentocommerce.com/community/canonical_url-1.3</pre>
<p>Refresh the Magento cache to enable the extension.</p>
<p><strong>Magento Community Edition 1.4.x, 1.5.x</strong></p>
<p>Magento 1.4 and 1.5 now support the canonical tag &#8220;out of the box&#8221;. To enable the tag for the category and product pages go to: <em>System=&gt;Configuration=&gt;Catalog=&gt;Search Engine Optimization</em> and enable: <em> </em><em>Use Canonical Link Meta Tag For Products</em> (and if you want &#8211; <em>Use Canonical Link Meta Tag For Categories</em>) : <em> </em></p>
<figure id="attachment_136" aria-describedby="caption-attachment-136" style="width: 518px" class="wp-caption alignnone"><a href="https://blog.gaiterjones.com/wp-content/uploads/2011/02/Image4.jpg"><img loading="lazy" decoding="async" class="hang-1-column      " style="border: 1px solid #dddddd;" title="Enable canonical Meta Tag in Magento 1.4, 1.5" src="https://blog.gaiterjones.com/wp-content/uploads/2011/02/Image4.jpg" alt="Enable canonical Meta Tag in Magento 1.4, 1.5" width="518" height="136" /></a><figcaption id="caption-attachment-136" class="wp-caption-text">Enable canonical Meta Tag in Magento 1.4, 1.5</figcaption></figure>
<p><strong>Confirm the Canonical Tag is correct<br />
</strong></p>
<p>Check the Canonical Tag is working by browsing to a product and checking the source HTML. In my demo store with Magento 1.3.x or with the Canonical Tag option deactivated in Magento 1.4, 1.5 the Nokia 2610 product page shows the category/product url <strong><em>http://dev.webshop.com/electronics/cell-phones/nokia-2610-phone.html</em></strong>, with the Yoast extension or canonical Meta Tags activated there is a more SEO friendly canonical link URL :</p>
<p>&lt;link rel=&#8221;canonical&#8221; href=&#8221;<strong><em>http://dev.webshop.com/nokia-2610-phone.html</em></strong>&#8221; /&gt;</p>
<h2>Configure the Open Graph Meta tags</h2>
<p>Now we have a static canonical URL for our products we need to configure the Open Graph meta tags Facebook will use to convert our page into a Facebook Open Graph object. Facebook says &#8220;The (Open Graph Meta) tags allow you to specify structured information about your web pages. The more information you provide, the more opportunities your web pages can be surfaced within Facebook today and in the future.&#8221;</p>
<p>Before we can add the meta tags we need to add the <em>xmlns:fb -attribute</em> to the xml name space element in our HTML header, this is so that Internet Explorer browsers can understand the Open Graph tags.</p>
<p>Locate the main <em>/template/page</em> folder for your Magento theme, for the default theme this is located in <em>app/design/frontend/base/default/template/page</em> for Magento 1.4.x, 1.5.x and <em>app/design/frontend/default/default/template/page</em> for Magento 1.3.x.</p>
<p>Open the main HTML <em>template phtml</em> file for your theme e.g. 2columns-right.phtml and locate the line of code with the opening HTML element:</p>
<pre class="brush:plain">&lt;html xmlns="http://www.w3.org/1999/xhtml" xml:lang="&lt;?php echo $this-&gt;getLang() ?&gt;" lang="&lt;?php echo $this-&gt;getLang() ?&gt;"&gt;</pre>
<p>Change this to</p>
<pre class="brush:plain">&lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://opengraph.org/schema/" xml:lang="&lt;?php echo $this-&gt;getLang() ?&gt;" lang="&lt;?php echo $this-&gt;getLang() ?&gt;"&gt;</pre>
<p>Now in the <em>template/page/html</em> folder open the <em>head.phtml</em> file and add the following code and Open Graph meta tags for your version of Magento directly under the existing META tags.  (Double click the code boxes and and use CTRL-C to copy the code.)</p>
<p><strong>Magento Community Edition 1.3.x with Canonical URL Extension</strong></p>
<pre class="brush:php">&lt;?php
/**
 * Facebook Open Graph meta tags Magento 1.3
 *
 */
?&gt;
&lt;!--Default OG Meta tags--&gt;
&lt;meta property="og:site_name" content="My eCommerce Store"/&gt;
&lt;meta property="og:street-address" content="1 THE High Street"/&gt;
&lt;meta property="og:locality" content="London"/&gt;
&lt;meta property="og:postal-code:" content="SW1"/&gt;
&lt;meta property="og:country-name:" content="United Kingdom"/&gt;
&lt;meta property="og:phone_number" content="00441234567890"/&gt;
&lt;meta property="og:latitude" content="00.00000000000000"/&gt;
&lt;meta property="og:longitude" content="00.00000000000000"/&gt;
&lt;?php // ***** Detect product or category page ?&gt;
&lt;?php if (Mage::registry('current_category')): ?&gt;
&lt;?php $cat=Mage::registry('current_category') ?&gt;
&lt;?php $catLevel=$cat-&gt;getLevel() ?&gt;
&lt;?php $catId=$cat-&gt;getId()  ?&gt;
&lt;?php $_id= Mage::app()-&gt;getRequest()-&gt;getParam('id', false)  ?&gt;
&lt;?php if($_id!=$catId):  ?&gt;
&lt;?php // Product page ?&gt;
&lt;!--Product page OG Meta tags--&gt;
&lt;meta property="og:title" content="&lt;?php echo trim(Mage::registry('current_product')-&gt;getName())?&gt;"/&gt;
&lt;meta property="og:type" content="product"/&gt;
&lt;?php if ($this-&gt;getHeadProductUrl()): ?&gt;
&lt;meta property="og:url" content="&lt;?php echo $this-&gt;_data['urlKey'] ?&gt;"/&gt;
&lt;?php endif; ?&gt;
&lt;meta property="og:description" content="&lt;?php echo strip_tags(str_replace("&lt;br /&gt;",", ",substr(Mage::registry('current_product')-&gt;getDescription(), 0, strpos(Mage::registry('current_product')-&gt;getDescription(), '.')+1))) ?&gt;"/&gt;
&lt;meta property="og:image" content="&lt;?php echo Mage::helper('catalog/image')-&gt;init(Mage::registry('current_product'), 'small_image')-&gt;resize(100,100);?&gt;"/&gt;
&lt;?php else: ?&gt;
&lt;?php // Category page ?&gt;
&lt;!--Category page OG Meta tags--&gt;
&lt;meta property="og:title" content="&lt;?php echo trim(Mage::registry('current_category')-&gt;getName())?&gt;"/&gt;
&lt;meta property="og:type" content="product"/&gt;
&lt;meta property="og:url" content="&lt;?php echo $this-&gt;helper('core/url')-&gt;getCurrentUrl() ?&gt;"/&gt;
&lt;meta property="og:description" content="&lt;?php echo htmlspecialchars($this-&gt;getDescription()) ?&gt;"/&gt;
&lt;?php if(trim(Mage::registry('current_category')-&gt;getImageUrl()=="")): ?&gt;
&lt;meta property="og:image" content="CATEGORY HAS NO IMAGE CONFIGURE MANUAL LINK TO A GENERIC CATEGORY IMAGE"/&gt;
&lt;?php else: ?&gt;
&lt;meta property="og:image" content="&lt;?php echo trim(Mage::registry('current_category')-&gt;getImageUrl())?&gt;"/&gt;
&lt;?php endif; ?&gt;
&lt;?php endif; ?&gt;
&lt;?php endif; ?&gt;
&lt;?php // ***** Detect CMS page ?&gt;
&lt;?php if(Mage::getSingleton('cms/page')-&gt;getIdentifier() == 'home'  &amp;&amp; Mage::app()-&gt;getFrontController()-&gt;getRequest()-&gt;getRouteName() == 'cms' ) : ?&gt;
&lt;!--Home page OG Meta tags--&gt;
&lt;meta property="og:title" content="THIS IS THE MAIN CMS HOME PAGE"/&gt;
&lt;meta property="og:type" content="product"/&gt;
&lt;meta property="og:url" content="&lt;?php echo $this-&gt;helper('core/url')-&gt;getCurrentUrl() ?&gt;"/&gt;
&lt;meta property="og:description" content="MY DESCRIPTION"/&gt;
&lt;meta property="og:image" content="MANUAL LINK TO A GENERIC IMAGE"/&gt;
&lt;?php endif; ?&gt;</pre>
<p>&nbsp;</p>
<p><strong>Magento Community Edition 1.4.x, 1.5.x</strong></p>
<pre class="brush:php">&lt;?php
/**
 * Facebook Open Graph meta tags Magento 1.4, 1.5
 * updated 16.05.2011
 */
?&gt;
&lt;!--Default OG Meta tags--&gt;
&lt;meta property="og:site_name" content="My eCommerce Store"/&gt;
&lt;meta property="og:street-address" content="1 THE High Street"/&gt;
&lt;meta property="og:locality" content="London"/&gt;
&lt;meta property="og:postal-code:" content="SW1"/&gt;
&lt;meta property="og:country-name:" content="United Kingdom"/&gt;
&lt;meta property="og:phone_number" content="00441234567890"/&gt;
&lt;meta property="og:latitude" content="00.00000000000000"/&gt;
&lt;meta property="og:longitude" content="00.00000000000000"/&gt;
&lt;?php // ***** Detect product or category page ?&gt;
&lt;?php if (Mage::registry('current_category')): ?&gt;
&lt;?php $cat=Mage::registry('current_category') ?&gt;
&lt;?php $catLevel=$cat-&gt;getLevel() ?&gt;
&lt;?php $catId=$cat-&gt;getId()  ?&gt;
&lt;?php $_id= Mage::app()-&gt;getRequest()-&gt;getParam('id', false)  ?&gt;
&lt;?php if($_id!=$catId):  ?&gt;
&lt;?php // Product page ?&gt;
&lt;!--Product page OG Meta tags--&gt;
&lt;meta property="og:title" content="&lt;?php echo trim(Mage::registry('current_product')-&gt;getName())?&gt;"/&gt;
&lt;meta property="og:type" content="product"/&gt;
&lt;?php if ($this-&gt;helper('catalog/product')-&gt;canUseCanonicalTag()): ?&gt;
&lt;meta property="og:url" content="&lt;?php echo trim(Mage::registry('current_product')-&gt;getProductUrl()) ?&gt;"/&gt;
&lt;?php endif; ?&gt;
&lt;meta property="og:description" content="&lt;?php echo strip_tags(str_replace("&lt;br /&gt;",", ",substr(Mage::registry('current_product')-&gt;getDescription(), 0, strpos(Mage::registry('current_product')-&gt;getDescription(), '.')+1))) ?&gt;"/&gt;
&lt;meta property="og:image" content="&lt;?php echo Mage::helper('catalog/image')-&gt;init(Mage::registry('current_product'), 'small_image')-&gt;resize(100,100);?&gt;"/&gt;
&lt;?php else: ?&gt;
&lt;?php // Category page ?&gt;
&lt;!--Category page OG Meta tags--&gt;
&lt;meta property="og:title" content="&lt;?php echo trim(Mage::registry('current_category')-&gt;getName())?&gt;"/&gt;
&lt;meta property="og:type" content="product"/&gt;
&lt;meta property="og:url" content="&lt;?php echo $this-&gt;helper('core/url')-&gt;getCurrentUrl() ?&gt;"/&gt;
&lt;meta property="og:description" content="&lt;?php echo htmlspecialchars($this-&gt;getDescription()) ?&gt;"/&gt;
&lt;?php if(trim(Mage::registry('current_category')-&gt;getImageUrl()=="")): ?&gt;
&lt;meta property="og:image" content="CATEGORY HAS NO IMAGE CONFIGURE MANUAL LINK TO A GENERIC CATEGORY IMAGE"/&gt;
&lt;?php else: ?&gt;
&lt;meta property="og:image" content="&lt;?php echo trim(Mage::registry('current_category')-&gt;getImageUrl())?&gt;"/&gt;
&lt;?php endif; ?&gt;
&lt;?php endif; ?&gt;
&lt;?php endif; ?&gt;
&lt;?php // ***** Detect CMS page ?&gt;
&lt;?php if(Mage::getSingleton('cms/page')-&gt;getIdentifier() == 'home'  &amp;&amp; Mage::app()-&gt;getFrontController()-&gt;getRequest()-&gt;getRouteName() == 'cms' ) : ?&gt;
&lt;!--Home page OG Meta tags--&gt;
&lt;meta property="og:title" content="THIS IS THE MAIN CMS HOME PAGE"/&gt;
&lt;meta property="og:type" content="product"/&gt;
&lt;meta property="og:url" content="&lt;?php echo $this-&gt;helper('core/url')-&gt;getCurrentUrl() ?&gt;"/&gt;
&lt;meta property="og:description" content="MY DESCRIPTION"/&gt;
&lt;meta property="og:image" content="MANUAL LINK TO A GENERIC IMAGE"/&gt;
&lt;?php endif; ?&gt;</pre>
<p>First we add the site default OG Meta Tags including two Facebook tags to identify the Facebook admininstrator ID for this content and an associated Application ID. Add your Facebook account ID and app ID here. To register a Facebook application simply login to Facebook,  goto <a href="http://www.facebook.com/developers/apps.php">http://www.facebook.com/developers/apps.php</a> and click on the &#8220;Set up new app&#8221; button. Give your app a name and set the domain name for the app &#8211; the domain name must match the domain the Like button is installed on for it to work, and save it. In the application settings or on the MyApp page you will see your Application ID number.</p>
<p>The information in these tags will be used by Facebook when they &#8220;scrape&#8221; your page the first time someone clicks on a product page Like Button.</p>
<p>Then we specify the Open Graph tags that will appear when we detect a product, category or cms pages. For CMS pages you need check for each CMS page name you wish to place a like button on, i.e. in the code example we are checking for a page called &#8220;home&#8221;. For CMS pages you need to also manually set the URL to an image. For category and sub category pages we can check for a configured category image, if non exists then use a manually configured default image. For products we will take the default image from the product. Bundled products are not currently being detected, will need to work on a solution for that&#8230;</p>
<p>If you want to include specific OG Meta tags for a page with a specific url then use.</p>
<pre class="brush:php">&lt;?php if($this-&gt;helper('core/url')-&gt;getCurrentUrl() === 'http://www.mystore.com/my-specific-page-url.htmll') : ?&gt;
&lt;!-- Specific Page OG Meta--&gt;
&lt;meta property="og:title" content="SPECIFIC PAGE OG CONTENT TITLE"/&gt;
&lt;meta property="og:type" content="product"/&gt;
&lt;meta property="og:url" content="&lt;?php echo $this-&gt;helper('core/url')-&gt;getCurrentUrl() ?&gt;"/&gt;
&lt;meta property="og:description" content="SPECIFIC PAGE CONTENT DESCRIPTION"/&gt;
&lt;meta property="og:image" content="http://www.mystore.com/myimage.jpg"/&gt;
&lt;?php endif; ?&gt;</pre>
<p>Edit the open graph data for your own requirements and add or remove more tags as you wish. The name, description and URL tags for product and category pages can be populated automatically. The URL for products comes from our canonical URL extension and the product description uses the same method I used for <a title="Magento SEO – Generate META Description Tags Automatically" href="https://blog.gaiterjones.com/magento-seo-generate-meta-description-tags-automatically/">SEO description meta tags</a>, to create a meaningful description to use within Facebook from the product long description text. The same method could be used for category pages too, for CMS pages you may need to manually enter the description for each CMS page you want a Like Button to appear on, and check for the page name using the code above.</p>
<p>More information on the Open Graph tags can be found <a href="http://developers.facebook.com/docs/opengraph/" target="_blank">here</a>.</p>
<p>Save your files and refresh a product page. Check the source HTML to check that the Open Graph tags have been populated correctly for product, category, sub category and cms pages i.e. :</p>
<pre class="brush:xml">&lt;!--Default OG Meta tags--&gt;
&lt;meta property="og:site_name" content="My eCommerce Store"/&gt;
&lt;meta property="og:street-address" content="1 THE High Street"/&gt;
&lt;meta property="og:locality" content="London"/&gt;
&lt;meta property="og:postal-code:" content="SW1"/&gt;
&lt;meta property="og:country-name:" content="United Kingdom"/&gt;
&lt;meta property="og:phone_number" content="00441234567890"/&gt;

&lt;meta property="og:latitude" content="00.00000000000000"/&gt;
&lt;meta property="og:longitude" content="00.00000000000000"/&gt;
&lt;!--Product page OG Meta tags--&gt;
&lt;meta property="og:title" content="Nokia 2610 Phone"/&gt;
&lt;meta property="og:type" content="product"/&gt;
&lt;meta property="og:url" content="http://dev150.webshop.com/nokia-2610-phone.html"/&gt;
&lt;meta property="og:description" content="The Nokia 2610 is an easy to use device that combines multiple messaging options including email, instant messaging, and more."/&gt;
&lt;meta property="og:image" content="http://dev150.webshop.com/media/catalog/product/cache/1/small_image/100x100/9df78eab33525d08d6e5fb8d27136e95/n/o/nokia-2610-phone-2.jpg"/&gt;</pre>
<h2>Add the Magento Facebook Like Button &#8211; XFBML or IFrame?</h2>
<p>Now we are all prepared to add our Like Button. You can render the Like Button and javascript code using two methods, XFBML or Iframe. There are pros and cons to both and you might already be averse to using Iframes on your pages. They both achieve the same result with the main difference being that the XFBML is slightly more versatile (and also perhaps quicker) allowing for a comment to be left after you have clicked the button, and also providing methods to trigger actions after the click.</p>
<p>Best practice recommends using XFBML but there is another reason for using the Iframe version that might interest you. If you sell the same product in multiple stores for example a Retail and a Wholesale store and the stores have different domains then using XFBML will result in two entries for the same product within Facebook because the domain name in the URL for the product must match the domain name of the page that executes the XFBML code. Using the Iframe method allows us to specify the domain ourselves and due to the nature of an Iframe Facebook has no way of confirming if it matches  the domain of the parent page of the Iframe or not. Another way to illustrate this is that if you develop your XFBML Facebook Like button on your development server and make test &#8220;Like&#8221; clicks on product X, Facebook will see this as <em>http://your.develeopment.server/productX</em> when you move the code to your live server, your &#8220;Likes&#8221; will be lost because Facebook will now register a new Open Graph object at <em>http://your.live.server/productX</em>. Whereas using the Iframe we can specify<em> http://your.live.server/productX</em> as the URL both on the live and development server.</p>
<h2>Magento Facebook XFBML Like Button</h2>
<p>Lets implement the XFBML version first. To add the Like Button to our product pages we need to locate <em>view.phtml</em> in the <em>/template/catalog/product</em> folder of our theme. Open <em>view.phtml</em> and look for the element or div that renders the product-name, around about line 50. We can locate the Facebook like button directly under the product name in the default theme, or you can locate it where you wish on your themes product page either by moving the code or positioning the button using a CSS class. Add the following code first :</p>
<pre class="brush:php">&lt;div id="facebook_like_product_button"&gt;&lt;fb:like ref="product_page" layout="button_count" show_faces="false" colorscheme="light" width="500"&gt;&lt;/fb:like&gt;&lt;/div&gt;</pre>
<p>This defines how our button looks and there are various options that you can experiment with to get the button you want. Note the DIV ID (or class) can be changed/added to whatever you want to style or move the button within the page. Take a look at <a href="http://developers.facebook.com/docs/reference/plugins/like/">http://developers.facebook.com/docs/reference/plugins/like/</a> to experiment with the different button style options available. This is what they look like with <em>standard</em>, <em>button count</em> or <em>box count</em> layout styles :</p>
<figure id="attachment_125" aria-describedby="caption-attachment-125" style="width: 324px" class="wp-caption alignnone"><a href="https://blog.gaiterjones.com/wp-content/uploads/2011/02/Image2.jpg"><img loading="lazy" decoding="async" class=" " style="border: 1px solid #DDDDDD;" title="Examples of different Like Button render options" src="https://blog.gaiterjones.com/wp-content/uploads/2011/02/Image2.jpg" alt="Examples of different Like Button render options" width="324" height="161" /></a><figcaption id="caption-attachment-125" class="wp-caption-text">Examples of different Like Button render options</figcaption></figure>
<p>Now we need to pull the Javascript SDK code from Facebook. <a href="http://developers.facebook.com/docs/reference/javascript/" target="_blank">Facebook </a>says &#8220;The most efficient way to load the SDK in your site is to load it  asynchronously so it does not block loading other elements of your page.   This is particularly important to ensure fast page loads for users and  SEO robots/spiders.&#8221; To access the SDK requires your Facebook application ID from Facebook. We can set the Like Button language with a locale code, add a translation for <em>en_US</em> to your Magento language files to change the language to match your store i.e. <em>de_DE</em> for German.</p>
<p>Add the following code next with your Facebook APP id, you can add it directly after the Button code on your product page if you will only be using like buttons on product pages. Or add it to your<em> header.phtml </em>template file to load it with every Magento page.</p>
<pre class="brush:xml">&lt;!-- Facebook Like Product Button BEGIN - load the SDK asynchronously --&gt;
	&lt;div id="fb-root"&gt;&lt;/div&gt;
		&lt;script&gt;
		/* &lt;![CDATA[ */
			window.fbAsyncInit = function() {
			FB.init({appId: 'YOUR FACEBOOK APP ID', status: true, cookie: true,
				xfbml: true});
		};
		(function() {
			var e = document.createElement('script'); e.async = true;
			e.src = document.location.protocol +
			'//connect.facebook.net/&lt;?php echo $this-&gt;__('en_US') ?&gt;/all.js';
			document.getElementById('fb-root').appendChild(e);
		}());
		 /* ]]&gt; */
		&lt;/script&gt;
&lt;!-- Facebook Like Product Button END --&gt;</pre>
<p>Notice that the Javascript code performs a protocol check to ensure that the link to Facebook matches the protocol of the page, i.e. HTTP or HTTPS, this is important when linking to external content to avoid browsers security errors when using an SSL connection.</p>
<h2>Testing</h2>
<p>Save your changes and refresh your product page to see your shiny new Like Button. Remember you should test all the popular browsers to ensure the code is working and the button displays correctly. Your browser tests should include, Internet Explorer, Firefox, Chrome, Opera and Safari and remember to test HTTPS access too. I also recommend that you <a href="http://www.asymptoticdesign.co.uk/cgi-bin/check-url.pl " target="_blank">check how your page looks to crawlers like Google Bot,</a> an error in the header of your page may render ok for normal browsers but not for a crawler bot. You can also do a page fetch test from within <a href="http://www.google.com/webmasters/tools" target="_blank">Google Webmaster Tools</a>. I learned this the hard way with a site becoming deindexed in Google due to a error in the header PHP code that was only being triggered by crawler Bots!</p>
<figure id="attachment_124" aria-describedby="caption-attachment-124" style="width: 518px" class="wp-caption alignnone"><a href="https://blog.gaiterjones.com/wp-content/uploads/2011/02/Image11.jpg"><img loading="lazy" decoding="async" class="hang-1-column    " style="border: 1px solid #dddddd;" title="Like Button - Magento 1.3.x Product Page Example" src="https://blog.gaiterjones.com/wp-content/uploads/2011/02/Image11.jpg" alt="Like Button - Magento 1.3.x Product Page Example" width="518" height="299" /></a><figcaption id="caption-attachment-124" class="wp-caption-text">Like Button - Magento 1.3.x Product Page Example</figcaption></figure>
<p>Go ahead and click on it (if you like it!) This will trigger Facebook to scrape your page and the &#8220;Like&#8221; should appear in your Facebook profile feed with the image, and title from your Open Graph tags.</p>
<figure id="attachment_196" aria-describedby="caption-attachment-196" style="width: 472px" class="wp-caption alignnone"><a href="https://blog.gaiterjones.com/wp-content/uploads/2011/02/liked-it1.jpg"><img loading="lazy" decoding="async" class="hang-1-column      " style="border: 1px solid #dddddd;" title="Facebook Marketing Like - example news feed post" src="https://blog.gaiterjones.com/wp-content/uploads/2011/03/facebook-like-example-updated.jpg" alt="Facebook Marketing Like - example news feed post" width="472" height="163" /></a><figcaption id="caption-attachment-196" class="wp-caption-text">Facebook Marketing Like - example news feed post</figcaption></figure>
<p>To add the Like Button to a category page add the same Button code above to locate <em>view.phtml</em> in the <em>/template/catalog/category </em>folder of your theme. Open <em>view.phtml</em> and look for the element or div that renders the category-name and add the code just below it. Note that depending on your theme there will be multiple occurences of the category name for different category views in this file.</p>
<figure id="attachment_322" aria-describedby="caption-attachment-322" style="width: 417px" class="wp-caption alignnone"><a href="https://blog.gaiterjones.com/wp-content/uploads/2011/02/magento-facebook-like-button-category-page1.jpg"><img loading="lazy" decoding="async" class="hang-1-column      " style="border: 1px solid #dddddd;" title="Magento Facebook Like button category page example" src="https://blog.gaiterjones.com/wp-content/uploads/2011/02/magento-facebook-like-button-category-page1.jpg" alt="Magento Facebook Like button category page example" width="417" height="205" /></a><figcaption id="caption-attachment-322" class="wp-caption-text">Magento Facebook Like button category page example</figcaption></figure>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Remember for Facebook to scrape your page the URL must be valid and accessible from the Internet, so if you are working on a development server it must be also accessible from the Internet. It can take a while for the Open Graph data to be collected and to appear correctly in Facebook. If you want to manually check that your Open Graph data is accessible use the Facebook Lint tool at <a href="http://developers.facebook.com/tools/lint">http://developers.facebook.com/tools/lint</a>. Enter the canonical URL of a product page and Facebook will return the scraped Open Graph meta data for you to verify.</p>
<figure id="attachment_134" aria-describedby="caption-attachment-134" style="width: 520px" class="wp-caption alignnone"><a href="https://blog.gaiterjones.com/wp-content/uploads/2011/02/Image32.jpg"><img loading="lazy" decoding="async" class="hang-1-column    " style="border: 1px solid #DDDDDD;" title="Verify Open Graph meta data with the Facebook Lint Tool" src="https://blog.gaiterjones.com/wp-content/uploads/2011/02/Image32.jpg" alt="Verify Open Graph meta data with the Facebook Lint Tool" width="520" height="323" /></a><figcaption id="caption-attachment-134" class="wp-caption-text">Verify Open Graph meta data with the Facebook Lint Tool</figcaption></figure>
<h2>Magento Facebook IFrame Like Button</h2>
<p>For completeness lets also look at implementing the Like Button using an IFrame, remember this can be useful because it allows <em>cross domain Like buttons</em>, i.e. buttons for the same content that will work when served from different website domains.</p>
<p>Unlike the XFBML code, the IFrame must specify the Like URL within the IFrame element so for Magento 1.3.x we need to generate the IFrame code in the header so that we can call the Canonical URL extension code. Add the following code at the end of <em>head.phtml </em>for <strong>Magento 1.3.x</strong></p>
<pre class="brush:xml">&lt;?php if (Mage::registry('current_product')) : ?&gt;
&lt;script type="text/javascript"&gt;
function fbLike(){
        return '&lt;iframe src="http://www.facebook.com/plugins/like.php?href=&lt;?php echo str_replace($this-&gt;getBaseUrl(),"http://www.YOUR-DOMAIN.com/",$this-&gt;_data['urlKey']) ?&gt;&amp;locale=&lt;?php echo $this-&gt;__('en_US') ?&gt;&amp;layout=button_count&amp;show_faces=false&amp;width=150&amp;action=like&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:150px; height:21px;" allowTransparency="true"&gt;&lt;/iframe&gt;';
    }
&lt;/script&gt;
&lt;?php endif; ?&gt;</pre>
<p>For <strong>Magento 1.4.x and 1.5.x </strong>you can either add the IFrame code directly to<em> view.php</em> or call it with the Javascript function in <em>head.phtml</em>. To use the Javascript function add the following to <em>head.phtml</em></p>
<pre class="brush:xml">&lt;?php if (Mage::registry('current_product')) : ?&gt;
&lt;script type="text/javascript"&gt;
function fbLike(){
        return '&lt;iframe src="http://www.facebook.com/plugins/like.php?href=&lt;?php echo str_replace($this-&gt;getBaseUrl(), "http://www.YOUR-DOMAIN.com/", trim(Mage::registry('current_product')-&gt;getProductUrl())); ?&gt;&amp;locale=&lt;?php echo $this-&gt;__('en_US') ?&gt;&amp;layout=button_count&amp;show_faces=false&amp;width=150&amp;action=like&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:150px; height:21px;" allowTransparency="true"&gt;&lt;/iframe&gt;';
    }
&lt;/script&gt;
&lt;?php endif; ?&gt;</pre>
<p>This code generates the IFrame html using a Javascript function that is called from the product page. Note that to keep the URL constant we replace the base host and domain name to be used for the Like Button with the domain name of the host site (or whatever we want). Edit www.YOUR-DOMAIN.com to match the URL of your site/store.</p>
<p>Now open up <em>view.phtml</em> and as with the XFBML solution add the following code after the product name, or wherever you want within the product view page of your theme.</p>
<pre class="brush:xml">&lt;!-- Facebook Like Button BEGIN --&gt;
&lt;div id="fb-root"&gt;&lt;/div&gt;
&lt;script type="text/javascript"&gt;
document.write(fbLike());
&lt;/script&gt;
&lt;!-- Facebook Like Button END --&gt;</pre>
<p>This simply calls the Javascript function created in <em>head.phtml</em> which returns the HTML for the IFrame. For Magento 1.4, 1.5 you can also replace the script code directly with the IFrame code in <em>view.phtml</em>:</p>
<pre class="brush:xml">&lt;!-- Facebook Like Button BEGIN --&gt;
&lt;div id="fb-root"&gt;&lt;/div&gt;
&lt;iframe src="http://www.facebook.com/plugins/like.php?href=&lt;?php echo str_replace($this-&gt;getBaseUrl(), "http://www.YOUR-DOMAIN.com/", trim(Mage::registry('current_product')-&gt;getProductUrl())); ?&gt;&amp;locale=&lt;?php echo $this-&gt;__('en_US') ?&gt;&amp;layout=button_count&amp;show_faces=false&amp;width=150&amp;action=like&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:150px; height:21px;" allowTransparency="true"&gt;&lt;/iframe&gt;
&lt;!-- Facebook Like Button END --&gt;</pre>
<p>Refresh the product page to see the IFrame version of the Like Button.</p>
<h2>Positioning the Facebook Like Button</h2>
<p>To style the button or to adjust its position on the product view page wrap the Facebook code in a DIV i.e. &#8220;<em>facebook_like_product_button</em>&#8221; and create a matching style CSS ID or class. For example to pad the button out a little add the following to your CSS:</p>
<pre class="brush:css">/*Facebook Like Button*/
#facebook_like_product_button {
padding-top: 1em;
}</pre>
<h2>Like Button for your facebook page</h2>
<p>If you want your main home page like button to Like an existing Facebook page simple modify the Like button code to include the URL of your Facebook page:</p>
<pre class="brush:xml">&lt;fb:like href="http://www.facebook.com/YOUR.FACEBOOK.PAGE" ref="product_page" layout="button_count" show_faces="false" width="120"&gt;&lt;/fb:like&gt;</pre>
<h2>Conclusions</h2>
<p>Now that the like button is working you will want to check which products are receiving button clicks, use the Facebook Insight tool to look at the statistics for your product page Likes &#8211; <a href="http://www.facebook.com/insights/">http://www.facebook.com/insights/</a> You may need to first click the green &#8220;statistics for your domain&#8221; button to link your domain to your Facebook profile. You can also integrate reporting into Google Analytics, see the blog post below. Topics for another post include how to target customers that have liked your products individually by sending them specific product updates via Facebook.</p>
<p>Note that the code posted here was tested with <strong>Community Editions</strong> of Magento only.</p>
<p>In part two of this Social Media Marketing for Magento tutorial we will  integrate <a title="Magento Product Social Media Marketing Part 2 – the AddThis Toolbar" href="https://blog.gaiterjones.com/magento-product-social-media-marketing-addthis-toolbar/">300+ more Social Marketing destinations</a> into Magento product pages using the <em>AddThis</em> toolbar.</p>
<h1><strong>More Reading</strong></h1>
<p><a href="http://www.saschakimmel.com/2010/05/how-to-capture-clicks-on-the-facebook-like-button/">http://www.saschakimmel.com/2010/05/how-to-capture-clicks-on-the-facebook-like-button/<br />
</a><a href="http://developers.facebook.com/docs/reference/plugins/like/"><br />
http://developers.facebook.com/docs/reference/plugins/like/</a></p>
<p><a href="http://developers.facebook.com/docs/best-practices/">http://developers.facebook.com/docs/best-practices/</a></p>
<p><a href="http://www.websharedesign.com/blog/how-do-i-track-that-little-facebook-like-button-in-google-analytics.html">http://www.websharedesign.com/blog/how-do-i-track-that-little-facebook-like-button-in-google-analytics.html</a></p>
<p><a href="http://developers.facebook.com/docs/opengraph/">http://developers.facebook.com/docs/opengraph/</a></p>
<p><a href="http://garethhooper.com/articles/social-media/45-integration/158-how-to-correctly-add-the-facebook-social-plugins-to-your-website.html">http://garethhooper.com/articles/social-media/45-integration/158-how-to-correctly-add-the-facebook-social-plugins-to-your-website.html</a></p>
<p>Updated Facebook Like Button</p>
<p><a href="http://soshable.com/facebook-like-butto">http://soshable.com/facebook-like-butto</a></p>
<p><a href="http://www.techi.com/2011/02/why-the-facebook-like-button-change-is-a-bait-and-switch/">http://www.techi.com/2011/02/why-the-facebook-like-button-change-is-a-bait-and-switch/</a></p>
<p><a href="http://davehiren.blogspot.com/2010/08/detect-product-page-in-magento.html">http://davehiren.blogspot.com/2010/08/detect-product-page-in-magento.html</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/magento-social-media-marketing-facebook-like-button/feed/</wfw:commentRss>
			<slash:comments>33</slash:comments>
		
		
			</item>
		<item>
		<title>Magento SEO &#8211; Generate META Description Tags Automatically</title>
		<link>https://blog.gaiterjones.com/magento-seo-generate-meta-description-tags-automatically/</link>
					<comments>https://blog.gaiterjones.com/magento-seo-generate-meta-description-tags-automatically/#comments</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Mon, 10 Jan 2011 17:04:57 +0000</pubDate>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[META Tag]]></category>
		<category><![CDATA[Product Description]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=46</guid>

					<description><![CDATA[Whilst some may argue that the META description tag has little SEO value, it is used by search engines to compile page &#8220;snippets&#8221; that are displayed next to the search...<a class="more-link" href="https://blog.gaiterjones.com/magento-seo-generate-meta-description-tags-automatically/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p>Whilst some may argue that the META description tag has little SEO value, it is used by search engines to compile page &#8220;snippets&#8221; that are displayed next to the search results, and these snippets should contain meaningful and good SEO content. When you add a new product in Magento you need to think about your SEO keywords, page title and META tag content. If you have a lot of products and have not created META description tag content for them then it can be a lot of work to update all the products maually, and more work to keep them up to date. There are a couple of ways to make this easier, you can export all your products, and edit the META description for each product and then reimport them into Magento which is a very slow process, or you can automatically create the META description based on your products long description, your products should at least have good descriptions!</p>
<p>Product descriptions in our Magento shop usually contain the product name in bold type on the first line, followed by a few good SEO keyword rich product description sentences. We can use this product description to create a nice META description tag with just a few lines of code in the head.phtml template file of your theme.</p>
<p>For example, if we look at the sample database products, the Nokia 2610 product description looks like this</p>
<figure id="attachment_49" aria-describedby="caption-attachment-49" style="width: 519px" class="wp-caption alignnone"><a href="https://blog.gaiterjones.com/wp-content/uploads/2011/01/magento-seo-description-meta-tag-2610-product2.jpg"><img loading="lazy" decoding="async" class="hang-1-column    " style="border: 1px solid black;" title="Automatic product description META tags in Magento" src="https://blog.gaiterjones.com/wp-content/uploads/2011/01/magento-seo-description-meta-tag-2610-product2.jpg" alt="" width="519" height="231" /></a><figcaption id="caption-attachment-49" class="wp-caption-text">Sample database product description</figcaption></figure>
<p>The description META tag from the sample database for this product looks like this &#8220;<em><strong>Offering advanced media and calling features without breaking the bank, The Nokia 2610 is an easy to use</strong></em>&#8221;</p>
<p>How about we use the product name and the first sentence from the description as the product description META tag for all our products? This can easily be accomplished by replacing the META description tag code in <strong>head.phtml </strong>located in your themes <em>template/page/html/</em> folder.</p>
<p>Replace:</p>
<pre class="brush:applescript">&lt;meta name="description" content="&lt;?php echo htmlspecialchars($this-&gt;getDescription()) ?&gt;" /&gt;</pre>
<p>With:</p>
<pre class="brush:php">&lt;?php if (Mage::registry('current_product')) : ?&gt;
&lt;?php if (strip_tags(str_replace("&lt;br /&gt;",", ",substr(Mage::registry('current_product')-&gt;getDescription(), 0, strpos(Mage::registry('current_product')-&gt;getDescription(), '.')+1)))=="") : ?&gt;
&lt;?php echo '&lt;meta name="description" content="'.htmlspecialchars($this-&gt;getDescription()).'" /&gt;' ?&gt;
&lt;?php else: ?&gt;
&lt;?php echo '&lt;meta name="description" content="'.strip_tags(str_replace("&lt;br /&gt;",", ",substr(Mage::registry('current_product')-&gt;getDescription(), 0, strpos(Mage::registry('current_product')-&gt;getDescription(), '.')+1))).'" /&gt;' ?&gt;
&lt;?php endif; ?&gt;
&lt;?php else: ?&gt;
&lt;?php echo '&lt;meta name="description" content="'.htmlspecialchars($this-&gt;getDescription()).'" /&gt;' ?&gt;
&lt;?php endif; ?&gt;</pre>
<p>This code will first check that we are working with a product page, it then takes the long product description text, replaces the first html line break with a comma, extracts the text to the first full stop and then strips out any markup tags. If the resulting description is empty then we revert to using the normal product META description.</p>
<p>The resulting slightly better looking META description tag for our product now looks like this <em>&#8220;<strong>Nokia 2610 Phone, The Nokia 2610 is an easy to use device that combines multiple messaging options including email, instant messaging, and more.</strong>&#8221; </em>Google will use this as the description snippet in search results. I use this same text for my <a href="https://blog.gaiterjones.com/automatic-magento-product-marketing-tweets-for-twitter/">automated product marketing tweets</a> and Facebook content too &#8211; more on that later.</p>
<p><strong>All </strong>our products should now have nicely formatted META description tags.  Play around with the str_replace function to extract the text you want from your product descriptions,  make sure you have your main SEO keywords in both the first sentence of your product description and your HTML Title and you are now on your way to better SEO content for all your products, and good looking content for your search engine description snippets.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/magento-seo-generate-meta-description-tags-automatically/feed/</wfw:commentRss>
			<slash:comments>24</slash:comments>
		
		
			</item>
		<item>
		<title>Automatic Magento Product Marketing Tweets for Twitter</title>
		<link>https://blog.gaiterjones.com/automatic-magento-product-marketing-tweets-for-twitter/</link>
					<comments>https://blog.gaiterjones.com/automatic-magento-product-marketing-tweets-for-twitter/#comments</comments>
		
		<dc:creator><![CDATA[PAJ]]></dc:creator>
		<pubDate>Tue, 28 Dec 2010 16:04:31 +0000</pubDate>
				<category><![CDATA[Magento]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Social Media Marketing]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[Marketing Tweets]]></category>
		<guid isPermaLink="false">http://blog.gaiterjones.com/?p=5</guid>

					<description><![CDATA[THIS MAGENTO HACK IS NOW A MAGENTO MODULE/EXTENSION, CLICK HERE FOR MORE INFO Wouldn&#8217;t it be great if your customers could do your twitter product marketing for you? Thats what...<a class="more-link" href="https://blog.gaiterjones.com/automatic-magento-product-marketing-tweets-for-twitter/" title="Continue reading">Continue reading</a>]]></description>
										<content:encoded><![CDATA[<p><a title="Magento Automated Social Media Marketing FREE Extension – Twitter, Facebook" href="https://blog.gaiterjones.com/magento-automated-social-media-marketing/"><strong>THIS MAGENTO HACK IS NOW A MAGENTO MODULE/EXTENSION, CLICK HERE FOR MORE INFO</strong></a></p>
<p>Wouldn&#8217;t it be great if your customers could do your twitter product marketing for you? Thats what I thought after seeing a few automated marketing posts coming up in my twitter feed. So I set about looking at my own automated marketing tweets triggered when a customer placed an order in our Magento e-commerce store. The goal was to randomly select a product from the last order &#8211; a so called &#8220;Top Seller&#8221;, wrap it up nicely in a 140 char tweet with a URL to the product page and post it to twitter automatically from the onepage checkout success page as the customer completed checkout. After a day or so of development I came up with a solution that looks something like this on Magento 1.3.3.0 using the test database.</p>
<figure id="attachment_17" aria-describedby="caption-attachment-17" style="width: 528px" class="wp-caption alignnone"><a href="https://blog.gaiterjones.com/wp-content/uploads/2010/12/Image12.jpg"><img loading="lazy" decoding="async" class="hang-1-column  " style="border: 1px solid black;" title="Example automated product marketing tweet" src="https://blog.gaiterjones.com/wp-content/uploads/2010/12/Image12.jpg" alt="Example automated product marketing tweet" width="528" height="102" /></a><figcaption id="caption-attachment-17" class="wp-caption-text">Example automated product marketing tweet</figcaption></figure>
<h2>Step 1 &#8211; Installing in Magento</h2>
<p>To integrate the code into Magento you can either use the onepage checkout success.phtml file to call the code after checkout, or if you have already developed your own Magento code modules you can create a new template phtml file and test the code by calling  it from a CMS block in Magento  i.e.</p>
<pre class="brush:xml">&lt;div&gt;{{block type="MY_Page/view" template="Page/tweet.phtml"}}&lt;/div&gt;</pre>
<p>If you use success.phtml you will need to submit an order from your webshop to test the code, if you are using CMS simply browse to the CMS page you created, i.e. <em>http://www.mysite.com/tweet</em></p>
<p>Here is the working code to use either in your own phtml template file or to append to success.phtml in your frontend themes template files.</p>
<pre class="brush:php">&lt;?php
// Magento Product Twitter Marketing
//
// paj
// www.gaiterjones.com
// tested with Magento 1.3.3.0
// v1.0

// Short URL function
function make_bitly_url($url,$login,$appkey,$format = 'xml',$history = 1)
{
//create the URL
	$bitly = 'http://api.bit.ly/v3/shorten?login='.$login.'&amp;apiKey='.$appkey.'&amp;uri='.urlencode($url). '&amp;format='.$format.'&amp;history='.$history;

//get the url
$response = file_get_contents($bitly);

//parse depending on desired format

	if(strtolower($format) == 'json')
		{
			$json = @json_decode($response,true);
			return $json['data']['url'];
		}
	elseif(strtolower($format) == 'xml') //xml
		{

			$xml = simplexml_load_string($response);
			return $xml-&gt;data-&gt;url;
		}
	elseif(strtolower($format) == 'txt') //text
		{
			return $response;
		}
}

// Get last order from Magento session.
$orderId = Mage::getModel('sales/order')-&gt;load(Mage::getSingleton('checkout/session')-&gt;getLastOrderId());
$order = Mage::getModel('sales/order')-&gt;load($orderId);
$items = $order-&gt;getAllItems();
$itemcount=count($items);
//$name=array();
//$unitPrice=array();
//$sku=array();
$ids=array();
//$qty=array();

try
{

// Build arrays, uncomment as needed to populate arrays with more order information, SKU, price etc.
foreach ($items as $itemId =&gt; $item)
{
	// $name[] = $item-&gt;getName();
	// $unitPrice[]=$item-&gt;getPrice();
	// $sku[]=$item-&gt;getSku();
	// we are only interested in the product id
	$ids[]=$item-&gt;getProductId();
	// $qty[]=$item-&gt;getQtyToInvoice();

//	echo $name[$itemId]. ' - ' .$sku[$itemId]. ' - €'. $unitPrice[$itemId]. '&lt;br&gt;';
}

	do {

	shuffle ($ids);
	$rand_keys = (count($ids) &gt; 1)?array_rand($ids, $itemcount):array_keys($ids);
	$custom = Mage::getModel('catalog/product')-&gt;load($ids[$rand_keys[0]]);

	// Make sure the product is visible in catalog
	if ($custom-&gt;getVisibility()==4) {

	// twitter text prefix, this will appear before your product description
	$twitter_txt=$this-&gt;__('Top Seller'). ": ";

	// twitter txt URL - add a short URL to the product using bit.ly API
	$shorturl=make_bitly_url($custom-&gt;getProductUrl(),'YOUR-BITLY-USERNAME','YOUR-BITLY-API');

	// The text between our tweet and the shorturl when the tweet is longer than 140 chars
	$twitter_txt_suffix = '... ';
	$chars_remaining=140-(strlen($shorturl)+strlen($twitter_txt_suffix));

	// debugging echos comment these out when testing complete.
	// Check lengths of short url, prefix etc.
	echo $shorturl. ' is '. strlen($shorturl). ' chars.&lt;br&gt;';
	echo 'Suffix and URL are '. (strlen($shorturl)+strlen($twitter_txt_suffix)). ' chars.&lt;br&gt;';
	echo 'Characters remaining for tweet : '. $chars_remaining. '&lt;br&gt;';

	// Prepare tweet text
	$twitter_txt=$twitter_txt . strip_tags(str_replace("&lt;br /&gt;",", ",substr($custom-&gt;getDescription(), 0, strpos($custom-&gt;getDescription(), '.')+1))). ' ';

	// Make sure we only tweet 140 chars or less

		if (strlen($twitter_txt) &lt;= $chars_remaining) {
			$twitter_txt = $twitter_txt; //do nothing
		}
		else {
			$twitter_txt = wordwrap($twitter_txt, $chars_remaining);
			$twitter_txt = substr($twitter_txt, 0, strpos($twitter_txt, "\n"));
			$twitter_txt = $twitter_txt. $twitter_txt_suffix;
		}

	// Complete tweet text with short url.
	$twitter_txt = $twitter_txt. ' ' .$shorturl;

	// Get ready to tweet
	$accessToken = file_get_contents("/home/www/classes/twitteroauth/access_token");
	$accessTokenSecret = file_get_contents("/home/www/classes/twitteroauth/access_token_secret");

	// Create our twitter API object
	require_once('/home/www/classes/twitteroauth/twitteroauth.php');
	$oauth = new TwitterOAuth('YOUR-TWITTER-CONSUMER-KEY', 'YOUR-TWITTER-CONSUMER-SECRET', $accessToken, $accessTokenSecret);

	// Send an API request to verify credentials
	$credentials = $oauth-&gt;get("account/verify_credentials");
	echo "Connected as @" . $credentials-&gt;screen_name. '&lt;br&gt;';

	// TWEEET, uncomment to tweet.
	//$oauth-&gt;post('statuses/update', array('status' =&gt; $twitter_txt));

	// debugging echos comment these out when testing complete.
	echo 'Simulated tweet : ('. strlen($twitter_txt). ' chars long.)&lt;br&gt;&lt;br&gt;';
	echo '&lt;strong&gt;'. $twitter_txt. '&lt;/strong&gt;&lt;br&gt;';

	}

	} while ($custom-&gt;getVisibility()!=4);

// debugging use this to catch any errors, remove error message when testing complete.
} catch (Exception $ex) { echo "An Error was detected."; }		

?&gt;</pre>
<p>Copy and paste the code at the end of your one page checkout success.phtml file or paste it into a new template phtml file i.e. tweet.phtml.</p>
<p>The first function is used to create a shortened URL via the bit.ly API, for this you will need a bit.ly account and your bit.ly API key (available form the settings menu in your account). We are only really interested in the product ids from the order, but if you want to use other information in your tweet remove the comments from the array loop.</p>
<p>$twitter_txt contains our tweet text. It starts out with a prefix &#8220;Top Sellers&#8221; and then uses an excerpt from the Magento product description to create the rest of the tweet text.</p>
<pre class="brush:php">$twitter_txt=$twitter_txt . strip_tags(str_replace("&lt;br /&gt;",", ",substr($custom-&gt;getDescription(),0, strpos($custom-&gt;getDescription(), '.')+1))). ' ';</pre>
<p>My product descriptions text always includes the product name on the first line of the long description text followed by a line break e.g.</p>
<pre class="brush:groovy">&lt;p&gt;&lt;strong&gt;Nokia 2610 Phone&lt;/strong&gt;&lt;br /&gt;The Nokia 2610 is an easy to use device that combines multiple messaging options including email, instant messaging, and more.</pre>
<p>We strip out the HTML replacing the first html line break with a comma and then search for the next full stop to extract the first sentence from our description. (This is also a good technique I have used  for<a href="https://blog.gaiterjones.com/magento-seo-generate-meta-description-tags-automatically/"> automatic SEO meta description tags for products</a>.)  If your product descriptions do not include line breaks you will need to play with this code so that it extracts a product description that suits your requirements.</p>
<p>We need to make sure our tweet including prefix and short url are less than 140 chars so we use some code to check how long the tweet product description text is and shorten it if required adding a &#8220;&#8230;&#8221; suffix. Now we have our tweet text and call the Twitter oAuth code to authenticate and post the tweet. The code that makes the tweet is commented, and for testing the tweet text will be echoed out so you can easily debug your tweet and description text, the simulated tweet should look something like this:</p>
<pre>http://bit.ly/hd6Et1 is 20 chars.
Suffix and URL are 24 chars.
Characters remaining for tweet : 116
Connected as @your-twitter-username
Simulated tweet : (135 chars long.)
<strong>Top Seller: Nokia 2610 Phone, The Nokia 2610 is an easy to use device </strong><strong>that combines multiple messaging options... http://bit.ly/hC6Et1</strong></pre>
<figure id="attachment_25" aria-describedby="caption-attachment-25" style="width: 519px" class="wp-caption alignnone"><a href="https://blog.gaiterjones.com/wp-content/uploads/2010/12/Image5.jpg"><img loading="lazy" decoding="async" class="hang-1-column     " style="border: 1px solid black;" title="Debugging the tweet text from a CMS page" src="https://blog.gaiterjones.com/wp-content/uploads/2010/12/Image5.jpg" alt="Debugging the tweet text from a CMS page" width="519" height="266" /></a><figcaption id="caption-attachment-25" class="wp-caption-text">Debugging the tweet text from a CMS page</figcaption></figure>
<p>See below for setting up your twitter application and installing the oAuth code.</p>
<p>Note that you need to have an order in the current magento session, I haven&#8217;t yet figured out how to access the last order outwith the user session, so if you don&#8217;t see anything or see the exception error echoed out make sure you are logged into your magento shop and have placed a test order.</p>
<h2>Step 2 &#8211; Twitter PHP oAuth Code</h2>
<p>The Twitter oAuth authentication process is complex and way beyond my programming skills, however <a href="http://abrah.am/">Abraham Williams</a> has developed the PHP code to perform the twitter oAuth authentication and posting for us. Download the code <a href="https://github.com/abraham/twitteroauth/zipball/0.2.0-beta3">here</a>. Open the ZIP folder and extract the twitteroauth folder to a suitable area on your development host. For example /home/www/classes. The folder contains two PHP files, twitteroauth.php and OAuth.php that are called from our code, update the script include so that the path to your oAuth files is correct.</p>
<h2><strong>Step 3 &#8211; Twitter Application and Access Codes</strong></h2>
<p>Obviously to create a twitter app you need a twitter account. Login to your twitter account and go to <a href="http://dev.twitter.com/apps/new" target="_blank">http://dev.twitter.com/apps/new</a> to register a new twitter app.  Complete the registration by choosing an application name, note this name will appear under your posts! Set the application type to client and make sure you set the application type to read &amp; write.</p>
<p>When you have registered your application take a note of the <strong>Consumer Key</strong> and <strong>Consumer Secret</strong>. Click on the My Access Token right hand menu link and take a note of your <strong>Access Token (oauth_token)</strong> and <strong>Access Token Secret (oauth_token_secret)</strong>.</p>
<p>Copy and paste your Twitter Consumer Key and Consumer Secret into the script.</p>
<pre class="brush:php">$oauth = new TwitterOAuth('YOUR-TWITTER-CONSUMER-KEY','YOUR-TWITTER-CONSUMER-SECRET', $accessToken, $accessTokenSecret);</pre>
<p>The Twitter Access Token and Access Token Secret can be included in plain text in the script but for security I am separating them out into two seperate files located with my oauth PHP scripts:</p>
<pre class="brush:php">$accessToken = file_get_contents("/home/www/classes/twitteroauth/access_token");
$accessTokenSecret = file_get_contents("/home/www/classes/twitteroauth/access_token_secret");</pre>
<p>So either modify the strings above to contain your access codes as plain txt i.e. $accessToken=&#8221;MY-ACCESS-TOKEN&#8221;;  or create your own folder and paths to two files containing your twitter access keys in plain text.</p>
<h2>Step 4 &#8211; Test</h2>
<p>If you have copied the code to your success.phtml file make an order and you should see the simulated tweet with your product description on your one page checkout success page.</p>
<pre>http://bit.ly/hd6Et1 is 20 chars.
Suffix and URL are 24 chars.
Characters remaining for tweet : 116
Connected as @your-twitter-username
Simulated tweet : (135 chars long.)
<strong>Top Seller: Nokia 2610 Phone, The Nokia 2610 is an easy to use device </strong><strong>that combines multiple messaging options... http://bit.ly/hC6Et1</strong></pre>
<p>To make a test tweet uncomment the tweet statement and place another order, check your twitter account for a new tweet!</p>
<p>When you are happy with your tweet text, uncomment the debugging echos from the script and test again.</p>
<figure id="attachment_17" aria-describedby="caption-attachment-17" style="width: 528px" class="wp-caption alignnone"><a href="https://blog.gaiterjones.com/wp-content/uploads/2010/12/Image12.jpg"><img loading="lazy" decoding="async" class="hang-1-column   " style="border: 1px solid black;" title="Example automated product marketing tweet" src="https://blog.gaiterjones.com/wp-content/uploads/2010/12/Image12.jpg" alt="Example automated product marketing tweet" width="528" height="102" /></a><figcaption id="caption-attachment-17" class="wp-caption-text">Example automated product marketing tweet</figcaption></figure>
<h2><strong>Conclusions and further ideas</strong></h2>
<p>Twitter marketing can easily become Twitter spam, depending on how many orders a day your shop is getting you may need to throttle back the number of product tweets you make, the tweet could also be handled elsewhere in the app, or from a cron job that picks a random product each day. I like the idea of the &#8220;Top Seller&#8221; from an actual order, and that the customer was actually doing the marketing work for you! You may also want to extract your parent categories to create additional hash tags for your tweets to improve search results, although this will eat up your precious 140 chars.</p>
<p>Some Googled resources used in creating this solution:</p>
<p><a href="http://articles.sitepoint.com/article/oauth-for-php-twitter-apps-part-1">http://articles.sitepoint.com/article/oauth-for-php-twitter-apps-part-1</a><br />
<a href="http://subesh.com.np/2010/03/ordered-items-detail-order-id-magento/">http://subesh.com.np/2010/03/ordered-items-detail-order-id-magento/</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.gaiterjones.com/automatic-magento-product-marketing-tweets-for-twitter/feed/</wfw:commentRss>
			<slash:comments>7</slash:comments>
		
		
			</item>
	</channel>
</rss>
