I already wrote a post about Publicize, the wonderful Jetpack module which allows any wordpress editor to share custom messages about their published posts over most Social Networks like Twitter, Facebook, Google Plus and the like. Needless to say, the magic will only happen if the WordPress Blog have one or more social accounts and connected them properly by following this brief guide, which is summarized by the following screen:
Once the setup is complete, Publicize will automatically fill in the text to send to your Social Network by entering the title of our article in the Custom Message box contained in its own widget to the right side of the insert/edit post page: if we're not happy with the title, we're also free to edit the default content according to our needs.
This handy feature is a godsend for most bloggers, to the point that Publicize is without a doubt one of the most useful modules of the whole Jetpack suite. Even if the plugin is awesome, we could still notice some minor flaws: for example, we could say that, at least with the current build, its configuration options are still pretty sparse. There's no way to automatically insert hashtags, maybe using the post user-defined tags or by parsing another custom field: this would be an extremely handy feature, to the point that it's already offered by many plugins dealing with auto-social publishing including the excellent Revive Old Post - which I'm eager to review in an upcoming article.
In order to fill this specific gap I created a small plugin that does exactly that. It goes by the name of...
Using the plugin is quite simple: once installed, the post tags with will be converted into hashtags and then appended to the Publicize Widget's Custom Message box after each command implying Save Post. The result would be just like this:
As said, the plugin will do its job each time you save the post: meaning that the hashtags will automatically appear when you'll use any command such as save as draft, update, publish, edit or other similar commands. he plugin also includes a dupe-check feature to prevent duplicate hashtags, so you won't have to worry about the same hashtag being added more than once.
Main Features
- Hashtags are created by picking the manually-assigned post tags, removing any spaces.
- The author/editor will still be able to manually insert one or more custom hashtags, exactly like before: any automatic hashtag - if not already added - will be appended after them.
- Hashtags can be reordered at will, regardless of how they were added (manually or automatically).
- The plugin features a dupe-check, ensuring that the same hashtag won't be added multiple times.
- The plugin will automatically check the Custom Message character length size in order to ensure it doesn't exceed a certain number of characters (118 by default). This number can be also manually changed or set to zero in order to shut-down the max-length check entirely.
Installing the plugin
The plugin is completely free and has been released under the GPL v. 2.0 license: you can download and/or install the latest version by visiting the Plugin's page in the WordPress Plugin Browser.
Source Code
If you are interested in to take a look at the plugin's source code or you want to make your very own custom build, you can review the Publicize With Hashtags v0.1.2 source code with full developer's comments: feel free to use it as you like.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
/* Plugin Name: Publicize With Hashtags Plugin URI: https://www.ryadel.com/works/publicize-with-hashtags/ Description: Automatically append hashtags to any content sent by Jetpack's Publicize module: hashtags will be created using post tags: dupe check and an optional length-based threshold are also included. Version: 0.1.2 License: GPLv2 or later Author: Darkseal Author URI: https://www.ryadel.com/ */ // If Jetpack is not installed or Publicize module isn't active, just exit now. if (!class_exists('Jetpack') || !Jetpack::is_module_active('publicize')) return; function publicize_with_hashtags() { // Set an optional character threshold (set to null to disable). // If you set it as a positive integer, hashtags will be appended only until this threshold is reached. // Default is 118, which is good for Twitter considering a default, non-https url length, which is 22 chars as stated by Twitter standards. // For more info, see https://dev.twitter.com/overview/api/counting-characters and https://dev.twitter.com/overview/t.co Twitter official docs. // Suggested values: // 118 if you plan to use only HTTP URLs // 117 if you plan to use both HTTP and HTTPS (or only HTTPS) URLs // 140 if you don't plan to append URL infos to your posts // 0 or <null> or <false>, if you want to tufn-off this check and append hashtags without any char limits - good if you're only using Facebook sharing. $mess_max_length = 118; // Set it to TRUE to strip all spaces when converting Tags to Hashtags, i.e. 'Windows 8' -> '#Windows8', FALSE to keep only first. // Default is TRUE (strip all spaces). $strip_spaces = true; // meta tag used by Publicize to store social message. Change this only if you're really know what you're doing. // If you do and you feel like you should, please contact me so I'll update the plugin aswell. $meta = '_wpas_mess'; $p = get_post(); if (empty($p)) return; // Get the current post social message $mess = get_post_meta($p->ID, $meta, true); // Performance-wise length check: do nothing if we're already out of threshold. if (!empty($mess) && !empty($mess_max_length) && $mess_max_length <= (strlen($mess))) return; // Get the post tags array $ta = get_the_tags($p->ID); // Performance-wise tag check: do nothing if we don't (yet) have tags to process. if (empty($ta)) return; // From now on, we mean business. Let's start by initializing the social message (if needed). if (empty($mess)) $mess = ''; // Create list of tags with hashtags in front of them until threshold is reached foreach ($ta as $t) { // Create the hashtag, stripping spaces if needed. $ht = '#' . (($strip_spaces) ? str_replace(' ', '', $t->name) : $t->name); // only process newly-added hashtags, skipping duplicate ones if (stripos($mess,$ht) === false) { if (!empty($mess_max_length) && $mess_max_length <= (strlen($mess) + strlen($ht))) break; $mess .= ' '.$ht; } } // Update the new social message update_post_meta($p->ID, $meta, $mess); } // Hook the plugin action to 'save_post' handler. add_action('save_post', 'publicize_with_hashtags', 99); |
You can also check out the latest version at GitHub.
If you chose to go with your own build, you can install it by following this great guide to functionality plugins by Eric Dye or through the handy Functionality Plugin developed by Shea Bunge.
Useful Links
- Publicize With Hashtags on ryadel.com.
- Plugin official Page on the WordPress Plugin Browser.
- GitHub project page and its related Source Code Repository.
- Official SVN repository on WordPress.org.
- PayPal Donate Link, if you like the plugin and would like to support us.
YOU are THE hero of the day! was searching for this. THANK YOU. works like a charm
Thanks for this plugin. I’m trying to change the message to have the content instead of the title.
I changed $mess = $p->post_title to $mess = $p->post_content but this isn’t working. Any ideas please?
I am using Joomla for my website, which is where my blog is located as well, so I am not using even one of the plug-ins you mentioned here. There are a number of plug-ins that I would love to use though, in time…when I have my own WordPress blog
‘Publicize With Hashtags’ plugin tags that automatically become hashtags in publicize only apply to posts, how do I make them apply to custom posts too? thanks
I never implemented that: if you need it, I could release a new version…
yes, I need a custom post type, thanks
about when release a new version?
now it’s too late!!
not working now