WordPress and Mastodon Social Media Integration

Share on Mastodon WordPress Plugin - Autopost to Mastodon

The Mastodon social media platform is steadily gaining more popularity as Twitter and Facebook users tire of timelines manipulated for political purposes. For those who are part of the federating social network, there are plugins that allow you to automatically share new WordPress posts as toots (same as Twitter’s tweets).

While Mastodon Autopost seems to be one of the most popular Mastodon server WordPress integrations, we couldn’t get it working with WordPress 5.8.2. 

The Share on Mastodon WordPress plugin works without issue and is covered below.

Automatically Post to Mastodon Social Media Account

  1. Install and enable the “Share on Mastodon” WordPress plugin.
  2. In the WordPress dashboard under “Settings,” select “Share on Mastodon.”
  3. Type in your Mastodon instance URL.
    Share on Mastodon plugin settings
  4. Check the “Post” checkbox.
  5. Save changes.
  6. Near the bottom select “Authorize Access.” 
  7. Log into Mastodon, then select “Authorize” to allow WordPress to upload media files and posts as Mastodon toots.
    Authorize WordPress and Mastodon social media account integration
  8. Create or edit a WordPress post.
  9. On the bottom of the post sidebar, you’ll see a “Share on Mastodon” section, with the feature enabled (checked) by default.
    Post will be tooted once published or updated

    Publish or update the post.
  10. The Mastodon section will now display a direct link to the toot.
    Post shared on Mastodon and direct link

    If you delete the linked toot at any point, you’ll need to unlink the old URL in WordPress to retoot the post.

Though there aren’t additional features in the dashboard for the Mastodon integration (as of version 0.6.4), the plugin developer offers code snippets to further customize automated toots. To make adjustments, log into SSH (or cPanel Terminal) and navigate to your WordPress root directory. Now edit the plugin PHP file.

nano wp-content/plugins/share-on-mastodon/share-on-mastodon.php

To include WordPress post tags as hashtags in Mastodon toots for social media search engine optimization (SEO), add the following to the bottom of the PHP file:

add_filter( 'share_on_mastodon_status', function( $status, $post ) {
  $tags = get_the_tags( $post->ID );
  if ( $tags ) {
    $status .= "\n\n";
    foreach ( $tags as $tag ) {
      $status .= '#' . preg_replace( '/\s/', '', $tag->name ) . ' ';
    }
    $status = trim( $status );
  }
  return $status;
}, 11, 2 );

To change a toot’s visibility from public to private, add the following:

add_filter( 'share_on_mastodon_toot_args', function( $args ) {
  $args['visibility'] = 'private'; // Only followers will get to see this message.
  return $args;
} );

Learn more about the auto-posting to the Mastodon social media network at https://github.com/janboddez/share-on-mastodon.

For the most secure WordPress site, you need secure hosting. That’s why InMotion Hosting created their own WordPress Hosting package with rigorous server-side security - so you can spend less time hardening your hosting and more time creating your website.

View WordPress Hosting Plans

J
Jacqueem Content Writer I

Technical writer focused on cybersecurity and musicianship.

More Articles by Jacqueem

Comments

It looks like this article doesn't have any comments yet - you can be the first. If you have any comments or questions, start the conversation!

Was this article helpful? Let us know!