Jetpack Publicize and Twitter Hashtags

Photo by: Rayi Christian Wicaksono

I love the Jetpack WordPress plugin from Automatic. This one plugin does many things that require multiple plugins including traffic analysis, enhanced security and speed boosts. Using the one plugin reduces the amount of code running on my site. It also means I only have one plugin to update instead of many.

Jetpack has a feature called Publicize.

Publicize makes it easy to share your site’s posts on several social media networks automatically when you publish a new post.

I configured Publicize to send my post links to Twitter, Facebook, Tumblr and a number of other social media sites. I have the option of adding a custom message to be posted to my Twitter account. If I leave the custom message area blank, Publicize will use the title of my post as the custom message texts. The Publicize feature works well but one thing bothered me.


I always add WordPress tags to my post. But I wanted the WordPress tags posted as Twitter hashtags when Publicize posts the message. Hashtags help people find your content on Twitter. After reading the Jetpack documentation I started looking around on Google. Using the search phrase, "does jetpack support twitter hashtags", I found a link to a discussion on

Jeremy Herve provided a possible solution using the Functionality plugin and a bit of code.

A functionality plugin is a way to separate what you might normally place in a theme's functions.php file, and put it in a plugin instead. It works the same way as a theme functions.php file, but is separate from the theme and so not affected by theme upgrades, or tied to the theme so you lose all of your functions if you choose to switch themes.

Jeremy’s solution added WordPress categories as Twitter hashtags to the custom message entered into the Publicize. After reading up on WordPress functions I installed Functionality and modified Jeremy's code to use WordPress tags instead of categories.

This post will be a test of whether this works.

/* Plugin Name: Island in the Net Plugin URI: Description: A site-specific functionality plugin for Island in the Net where you can paste your code snippets instead of using the theme's functions.php file Author: Khürt Williams Author URI: Version: 2015.02.23 License: GPL */ if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'publicize' ) ) { function island_publicize_hashtags( ) { $post = get_post(); if ( !empty( $post ) ) { /* Grab the tags of the post */ $post_tags = get_the_tags( $post->ID ); /* Append tags to custom message */ 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; } /* Create our custom message */ $custom_message = get_the_title( $post->ID ) . '' . $hash_tags; update_post_meta( $post->ID, '_wpas_mess', $custom_message ); } } } /* Save that message */ function island_cust_pub_message_save( ) { add_action( 'save_post', 'island_publicize_hashtags' ); } add_action( 'publish_post', 'island_cust_pub_message_save' ); } }

more code

if ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'publicize' ) ) { function island_publicize_hashtags( ) { } }