Skip to content

pelmered/ShareBird

Repository files navigation

ShareBird social buttons

###Share the Word, with ShareBird!

The philosophy of this plugin is to be fast, slim and developer friendly. The most prominent thing you will notice is that there is no settings and admin interface, however it is very easy to customize the plugin using WordPress hooks. It's very easy and straight forward. Read the documentation below to get started.

Based on SimpleShareButtons by Andreas Norman (SubZane).

Please note that this plugin is stil under early development and the API(hooks and filters) may change without any notice untill we release version 1.0.0

####Default styling Demo

Screenshot1 - TwentyThriteen, default styling

Index

Supported services

The plugin currently supports the following services:

  • Facebook
  • Twitter
  • LinkedIn
  • Google+

Usage / Documentation

By default the plugin outputs all available buttons on single posts and pages with (priority 999).

You can customize which buttons are shown and where using filters.

Hooks - actions and filters

####Displayed buttons

You can remove services using the following filter:

add_filter( 'sharebird_buttons', function( $buttons )
{
	unset( $buttons['linkedin'] );
	return $buttons;
});

Default value: array('facebook', 'twitter', 'linkedin', 'googleplus')

####Button output locations

The plugin can display share buttons before the post content/excerpt, after, or both.

To display the buttons before and after the post content/excerpt, you can use this snippet:

add_filter( 'sharebird_output_positions', function( $positions )
{
	return array('before', 'after');
});

Default value: array('after')

####Output conditionals

You can use WordPress Conditional Tags to select where the output should be displayed. Example:

add_filter( 'sharebird_output_conditionals', function( $conditionals )
{
	return array( 'is_single', 'is_page' );
});

Default value: array('is_front_page', 'is_home', 'is_single', 'is_page', 'is_post_type_archive', 'is_singular')

####Output by post type

If you have selected is_post, is_page or is_singular in the output conditionals, you can use a filter to specify which post types the buttons are displayed for:

add_filter( 'sharebird_output_post_types', function( $post_types )
{
	return array( 'post' );
});

Default value: array('post', 'page')

#####Manual output in your theme

You can disable the output from the plugin altogether using:

add_filter( 'sharebird_default_output', '__return_false' );

Default value: true (bool)

Then, add this code wherever you want in your template:

if( class_exists( 'ShareBird' ) )
{
	ShareBird()->output_buttons();
}

####Customizing values / metadata

To customize the metadata(title, author name etc.) that are passed to the share popup you can change this in the tamplate file, or by using filters like this.

#####Customizing title Add tags at the end of the share text.

add_filter( 'sharebird_get_post_title', function( $post_title, $post_id )
{
	$tags = wp_get_post_tags( $post_id );

	foreach( $tags AS $tag )
	{
		$post_title .= '#'.$tag->name;
	}
	
	return $post_title;
}, 10, 2);

The same code, but only for Facebook

add_filter( 'sharebird_facebook_get_post_title', function( $post_title, $post_id )
{
	$tags = wp_get_post_tags( $post_id );

	foreach( $tags AS $tag )
	{
		$post_title .= '#'.$tag->name;
	}
	
	return $post_title;
}, 10, 2);

#####Customizing author

add_filter( 'sharebird_get_author', function( $post_author, $post_id )
{
	$post_author = 'myNickName'

	return $post_author;
}, 10, 2);

The same code but run only for Twitter

add_filter( 'sharebird_twitter_get_author', function( $post_author, $post_id )
{
	$post_author = 'myTwitterName';
	
	return $post_author;
}, 10, 2);

###Change HTML output (Templating)

Copy the default template, sharebird-buttons.php from the plugins templates/ folder to your themes root folder.

Example:

/wp-content/themes/your-theme/sharebird-buttons.php

You can define as many templates as you want. Just put the template files in you theme and use them like this:

ShareBird()->output_buttons( 'folder/my_button_template.php' );

This will use the template located in /folder/my_button_template.php

###Change CSS output

It is off course very simple to just extend the default styles to make them look the way you want. But if you want to include your own styles that can be made like this:

add_action( 'wp_enqueue_scripts', function() 
{
	//derigster default script
	wp_dequeue_style( 'sharebird-public-styles' );

	//Add your own custom script from theme folder
	wp_enqueue_style( 'my-sharebird-styles', get_template_directory_uri() . '/css/my-styles.css' );
});

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published