Jetpack: add hashtags to the twitter sharing button

A few days ago I explained how to add hashtags to the tweets sent out by Jetpack Publicize. But what about the tweets your read can send using the Jetpack Sharing buttons at the bottom of your posts?

Here is how to get tags from your posts, and add them as hashtags to the twitter sharing button. As always, you’ll want to paste that code in a functionality plugin.

function jeherve_custom_sharing_title() {
	$post = get_post();
	if ( empty( $post ) ) {

	// Create sharing title.
	$sharing_title = get_the_title( $post->ID );

	// Get the tags.
	$post_tags = get_the_tags( $post->ID );
	if ( ! empty( $post_tags ) ) {
		// Create list of tags with hashtags in front of them.
		$hash_tags = '';
		foreach ( $post_tags as $tag ) {
				$hash_tags .= ' #' . $tag->name;
		// Add tags to the title.
		$sharing_title .= $hash_tags;

	return $sharing_title;
add_filter( 'sharing_title', 'jeherve_custom_sharing_title', 10, 3 );

Hat tip to Ryan for the idea!

5 replies on “Jetpack: add hashtags to the twitter sharing button”

wympy says:

Great! But how can you do the same thing with facebook and google+ ?

Jeremy says:

The tags are added to each Publicized post, regardless of the platform.

wympy78 says:

Thanks Jeremy. In my case I have no active Publicize module. The tags are there, but only on Twitter

Jeremy says:

My bad, I thought you were commenting on the other post. :)

The trick here is that we can only prefill the sharing area for Twitter. Facebook and Google+ don’t offer options to add custom text to the sharing area.

I’m afraid you won’t be able to work around this limitation.

wympy78 says:

Ok now I understand everything. Thanks;)