[pmwiki-users] Add a tweet this button

Lars Eighner surname at larseighner.com
Wed Jun 20 00:10:05 CDT 2012

1) Create tweet.php in your cookbook.

<?php  if (!defined('PmWiki')) exit ();

Markup('tweet','block','/\\(:tweet (.*?):\\)/e',"tweet_this('$1')");

function tweet_this($text){
$string = '<a href="http://twitter.com/share" class="twitter-share-button" ' .
           'data-text="' . $text . '" data-count="none">Tweet</a>' .
           '<script type="text/javascript" '.
           ' src="http://platform.twitter.com/widgets.js"></script>' ;
return $string;

2) Add the following line to your config.php


3) Usage:

Insert the tweet button like this:

(:tweet Some text with some variables like {$Title} :)

Comment:  This is just cut and paste from Twitter.  It inserts a button
graphic served by Twitter.  The text shows up in the tweet when the user
clicks the button as starting text for the tweet.  The user can edit it.
The page url is include in the tweet. Standard page variables will be
substituted in the text, but I don't know how far this will go with fancy

I had installed these by enabling html with a and script tags.  After a very
vicious series of vandalism and hard-on-pill spam attacks, I've decide
enabling html is not such a good idea and especially not the script tag.

Related:  There is also a recipe in the PmWiki cookbook to allow you to
tweet from your pages, but in many cases you will really want visitors to
tweet about your pages to their followers, although of course you can use
this tweet button yourself.

Variations: consult the twitter api pages for ways to vary this script, for
example to have the url that accompanies the tweet point to the front door
of your wiki instead of to the particular page the button is on.

Lars Eighner
8800 N IH35 APT 1191 AUSTIN TX 78753-5266

More information about the pmwiki-users mailing list