Advanced Usage

paulredmond edited this page Sep 14, 2010 · 8 revisions
Clone this wiki locally

Tweet button can be invoked from a theme using the renderTweetButton() function. The parameters for this function are as follows:

renderTweetButton([,$attributes = array() [, $override = false [, $disable_options = false]]])

possible array keys include:

  • data-url: Url that will be included in the tweet (twitter will automatically shorten it)
  • data-via: Twitter account that will be included at the end of the tweet ‘ie. via @data-via-value’ (do not include the ‘@’ symbol in the value)
  • data-text: Text that will be included in the tweet by default (user can override before tweeting)
  • data-related: An additional twitter account that will be recommended to user after they tweet (do not include the ‘@’ symbol)
  • data-count: Configures the retweet count dislay option. Values include (vertical, horizontal, or none)

If auto-output is enabled in the tweetbutton options, renderTweetButton() will not output anything unless override is set to true.

If set to boolean true, tweetbutton options will be ignored. Only attributes from the $attributes array will be used. If data-url and data-via attributes are not set, Twitter will try to use the title and url of the current page.

if(function_exists('renderTweetButton')) {
	renderTweetButton(array('data-via' => 'baz'), false, true);

In the above example, the only attribute passed to the tweet_button object will be data-via, since options were disabled in the third function parameter.

It’s wise to test that the function is defined when implementing in the theme. If the plugin is disabled, this code will not cause a fatal error.