Jeremy Herve Avatar

That’s me. And my blog. In English and in French.


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 ) ) {
			return;
	}

	// 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!

Reactions on the Fediverse and on the ATmosphere

9 responses

  1. wympy Avatar

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


    1. Jeremy Avatar

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


  2. wympy Avatar

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


  3. wympy78 Avatar

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


    1. Jeremy Avatar

      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.


      1. wympy78 Avatar

        Ok now I understand everything. Thanks;)


  4. wympy78 Avatar

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


    1. Jeremy Avatar

      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.


      1. wympy78 Avatar

        Ok now I understand everything. Thanks;)



Continuez votre lecture / Keep reading

Discover more posts about or look at some of the posts suggested below.

Jeremy Herve
Jeremy Herve

WordPress, TV Series, music, kids, and board games. I think that’s probably the best way to define me in a few words. 🙂

I work at Automattic where I lead a team building tools for bloggers and creators. I talk a lot about WordPress things, but also about all things open source in general.

I post in English and in French.

I live in Brittany, France, so you’ll also find me sharing pictures from our beautiful region from time to time.

1,241 posts
194 followers