Fitz Thiar: Thinking For The Impatient

Writings And Opinions of Fitz Thiar. More or Less.

I’ve been toying with the notion of having WordPress act as the default authority for all of my social media posts, and thought it might be nice to roll my own version.

The goal is simple. Post to a category called Social Posts, and have those updates appear on Threads, Bluesky and Mastodon as native social updates. Not as posts that link back to my blog.

I tested sending the RSS feed for that category only to IFTTT and Zapier, and having those platforms post either directly or via Buffer, depending on their integrations.

This wasn’t something I wanted to spend money on, so IFTTT’s free tier was instantly ruled out.

Zapier was more promising, so I set about testing and realized that, even with their formatting options, there simply wasn’t enough information in the RSS feed to do what I wanted.

Threads doesn’t use tags, but does use a “topic,” and there was no way to pass that. Bluesky and Mastodon use tags, but social media tags don’t align with the tags on my blog, e.g., #socialmedia/social media.

Adding the additional information I wanted in each post to WordPress is actually rather simple using “custom fields” to hold additional metadata. These are easy enough to add manually, but I used the free version of the ACF (Advanced Custom Fields) plugin for ease of use and location rules, such as the fields only appearing when the “Social Posts” category is selected.

I would need to pass four pieces of information to Zapier via the RSS feed:

  • Topic: Threads doesn’t use tags, but does have a topic field.
  • Tags: the tags I want appended to the post on Blusky and Mastodon.
  • Image URL: If there’s an image in the post, send the direct URL instead of having Zapier try to figure it out.
  • Alt Text: For accessibility on all platforms.

I named my fields “social_topics”, “soical_tags”, “social_image_url” and “social_image_alt”.

This is what it looks like in a browser:

Then I wrote a little PHP code to drop in the functions.php file of my WordPress theme to write the contents of the custom fields as XML tags in the RSS output of just the “Social Posts” category.

This is the second version of the code. Cleaned up and more extensible than my original version, which was a bunch of “if” statements for every field.

You can extend or repurpose this code yourself simply by adding to or removing lines under $fields. Each line has the custom field name defined first, what it should be output as in the XML second, and finally making sure it’s properly escaped.

/**
* Add custom fields to the RSS feed for the 'social-posts' category only.
*/
function fitz_add_custom_fields_to_rss() {
if ( ! is_feed() || ! is_category( 'social-posts' ) ) {
return;
}
$post_id = get_the_ID();
$fields = [
'social_topics' => [ 'tag' => 'social_topics', 'escape' => 'esc_xml' ],
'social_tags' => [ 'tag' => 'social_tags', 'escape' => 'esc_xml' ],
'social_image_url' => [ 'tag' => 'social_image_url', 'escape' => 'esc_url' ],
'social_image_alt' => [ 'tag' => 'social_image_alt', 'escape' => 'esc_xml' ],
];
foreach ( $fields as $field_name => $config ) {
$value = get_field( $field_name, $post_id );
if ( ! empty( $value ) ) {
$escaped = $config['escape']( $value );
echo "<{$config['tag']}>{$escaped}</{$config['tag']}>\n";
}
}
}
add_action( 'rss2_item', 'fitz_add_custom_fields_to_rss' );

Normally, I would have created a child theme for my WordPress theme and added this code directly to the functions.php file. This way it would survive any updates made to the parent theme, but as I am on the WordPress Premiun plan, I do not have FTP or SFTP access and can’t create child themes.

I could have just put the code at the bottom of the existing functions.php, but I would risk everything breaking whenever the theme is updated, so I used the Code Snippets plugin instead to add the code.

Once that was complete, and I verified that the XML tags were appearing on the feed, I headed over to Zapier to build the “Zap”.

Because we have added the metadata into the RSS feed it makes things so much easier in Zapier. I had previously tried using Zapiers filter function to extract the image URL from the post content, but it always returned it with additional junk. Now that it’s a tag on it’s own, it means we can skip all filtering functions and build a simple two-branch publishing logic.

Once Zapier finds a new item on the RSS feed, it checks the content of that item to see if the “social_image_url” exists. If it doesn’t exist, it travels down one branch of posting rules, and if it does exist, it goes down the other.

Setting the posting rules for each site is simple, and you can construct posts by adding various sections from the RSS feed into the appropriate fields.

Once all of this has been tested, which I did by setting the output to Buffer to “draft”, all you have to do is decide your posting schedule or if you wan them to post immediately. You achieve that by setting the “Method” as “Add to Queue” or “Share Now” Or “Share Next” for each social network step.

Once Buffer posts to the social networks, your post will appear as a native post, not a post that links back to your WordPress site.

Here are some screenshots so you can see how it looks and works.

The first is the post as it might appear on this site. Obviously this would be formatted differently to appear as a nice “social posts” category”.

Then we have how the post appear in Buffer – with and without tags depending on the network. After that we have a Threads post, complete with “topic”, and a Bluesky post with the ALT text already populated.

Finally we have an example of when the post is pushed all the way through to Bluesky. A native post with an image, tags, and not automatically linked to my WordPress site even though it originated there.

And there you have it.

Once setup, you can use your WordPress blog as the definitive repository for all of your social posts (not replies obviously) and you can post from anywhere as long as you have access to a browser.

You could even take this further, and by defining other custom fields have even more granular control, including which platforms a post goes through, or even custom content per platform.

Unfortunately you will have to be on a paid Zapier plan to do this. I found this out the hard way when I quickly burned through the “Two tasks per Zap” limit of the free tier, and paying nearly $28 a month for Zapier is not currently worth it when I could just post to my site and do a copy-paste to Buffer.

I will be looking at other ways to do this, like seeing if I can edit what Jetpack posts, as it already has an interface for customizing what is sent to each network. Maybe I can have it strip out the Title and URL and replace the tags.

Or maybe come up with some other solution altogether.

Anyway, while I won’t be using this myself, it was a fun little project. I hope somebody gets some mileage out of it.

Leave a Reply

Discover more from Fitz Thiar: Thinking For The Impatient

Subscribe now to keep reading and get access to the full archive.

Continue reading