{"id":6765,"date":"2009-03-27T00:09:21","date_gmt":"2009-03-26T18:39:21","guid":{"rendered":"https:\/\/www.quickonlinetips.com\/archives\/?p=6765"},"modified":"2012-04-01T16:35:23","modified_gmt":"2012-04-01T11:05:23","slug":"tweetmeme-button-on-selected-wordpress-posts","status":"publish","type":"post","link":"https:\/\/www.quickonlinetips.com\/archives\/2009\/03\/tweetmeme-button-on-selected-wordpress-posts\/","title":{"rendered":"Show Tweetmeme Button on Selected WordPress Posts"},"content":{"rendered":"<p><img decoding=\"async\" class=\"size-full wp-image-6767 alignright\" title=\"tweetmeme badge\" src=\"https:\/\/www.quickonlinetips.com\/archives\/wp-content\/uploads\/tweetmeme-badge.jpg\" alt=\"tweetmeme badge\" width=\"65\" height=\"76\" align=\"left\" \/> Tweetmeme is a Digg-like site for popular links on Twitter. Using a Tweetmeme badge can be a helpful reminder for your readers to<strong> retweet it<\/strong> &#8211; and if my experience is anything to go by, Twitter does send targeted traffic to your blogs. Clicking on the Tweetmeme badge will direct you to your Twitter profile, with a tweet of the format <em>RT @tweetmeme &lt;post title&gt; &lt;post link&gt;<\/em>.<\/p>\n<p>Integrating Tweetmeme on your blog is as simple as entering some JavaScript code (provided on Tweetmeme website). In this<strong> WordPress hack<\/strong>, however, I&#8217;ll show you how to display the Tweetmeme button only on posts you decide &#8211; by using a custom field. This is crucial, because a Tweetmeme badge on a site announcement would be unprofessional, not to mention redundant.<\/p>\n<h2>PHP function to to display Tweetmeme badge<\/h2>\n<p>Since you would want to show the Tweetmeme badge on multiple pages (on single.php, index.php etc.),<strong> wrapping the code in a simple function<\/strong> is a good idea. We can then call this function wherever we want the badge to be displayed.<\/p>\n<p>Open up your theme&#8217;s <strong>functions.php<\/strong> file. At the end of the file, you will find a <code>?&gt;<\/code><\/p>\n<p>Place the code below just before that.<\/p>\n<pre><code>function tweetmeme(){\r\n?&gt;\r\n&lt;div style=\"float: left; margin: 5px 15px 5px 0;\"&gt;\r\n&lt;script type=\"text\/javascript\"&gt;\r\ntweetmeme_url = '&lt;?php the_permalink(); ?&gt;';\r\n&lt;\/script&gt;\r\n&lt;script type=\"text\/javascript\" src=\"http:\/\/tweetmeme.com\/i\/scripts\/button.js\"&gt;&lt;\/script&gt;\r\n&lt;\/div&gt;\r\n&lt;?php\r\n}\r\n<\/code><\/pre>\n<h2>PHP tag to display the badge<\/h2>\n<p>In <strong>single.php and index.php<\/strong>, place the code below just before the tag <em>&lt;?php the_content(); ?&gt;<\/em> or <em>&lt;?php the_excerpt(); ?&gt;<\/em>.<\/p>\n<pre><code>&lt;?php $check_sm = get_post_meta($post-&gt;ID, 'tweetmeme', $single = true);\r\nif($check_sm != '')\r\ntweetmeme();\r\n?&gt;\r\n<\/code><\/pre>\n<h2>Enabling the badge on posts<\/h2>\n<p>Enabling the Tweetmeme badge requires you to<strong> add a custom field <\/strong>to the post in question. On posts where you want to display the post, add a field named <strong>tweetmeme<\/strong> with a value <em>true<\/em>.<\/p>\n<p>You can also extend this hack to hide Tweetmeme badge only on posts where you enter a custom field, or show other badges (Digg, Stumble Upon etc.) selectively.<\/p>\n<p><em>Guest blogger Sumesh writes Blog Designed, a blog for tips and links on design, SEO and WordPress. You can also follow him on <a href=\"https:\/\/twitter.com\/sumesh\" rel=\"nofollow noopener\">Twitter<\/a>. If you have some tips to share, <a href=\"https:\/\/www.quickonlinetips.com\/archives\/guest-blogging\/\">write a guest article<\/a> on QOT.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Tweetmeme is a Digg-like site for popular links on Twitter. Using a Tweetmeme badge can be a helpful reminder for&#8230;<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","footnotes":""},"categories":[6,111],"tags":[44,49],"class_list":["post-6765","post","type-post","status-publish","format-standard","hentry","category-blogging","category-social-media","tag-guest-posts","tag-tutorials"],"_links":{"self":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts\/6765","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/comments?post=6765"}],"version-history":[{"count":0,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/posts\/6765\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/media?parent=6765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/categories?post=6765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.quickonlinetips.com\/archives\/wp-json\/wp\/v2\/tags?post=6765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}