Skip to content

Share on Pixelfed

Automatically share image posts on Pixelfed. You choose which Post Types are shared. (Sharing can still be disabled on a per-post basis.)

This plugin shares some 75%—not an exact number—of its code with Share on Mastodon. Both plugins rely on the “Mastodon v1 API” (which Pixelfed supports, too).

Installation

The easiest way to install this plugin is to, inside WP Admin, head to Plugins > Add New, and search for share on pixelfed, and click Install and then Activate. (Of course, manually installing the ZIP file is possible, too.)

Configuration

Tell the Share on Pixelfed settings page—visit Settings > Share on Pixelfed—about your instance URL, and make sure to hit Save Changes. You’ll then be able authorize WordPress to post on your behalf.

Select the Post Types for which sharing to Pixelfed should be possible, too. (Sharing can still be disabled on a per-post basis.)

Custom Formatting

By default, shared statuses look something like:

My Awesome Post Title https://url.to/original-post/

Pixelfed will not automatically turn that URL into a clickable link, but we can live with that.

If you’d rather format statuses differently, there’s a share_on_pixelfed_status filter.

Example: if the image posts you share are all very short, mostly plain-text messages and you want them to appear exactly as written and without a backlink, the following couple lines of PHP would handle that.

add_filter( 'share_on_pixelfed_status', function( $status, $post ) {
  $status = wp_strip_all_tags( $post->post_content );
  return $status;
}, 10, 2 );

Image Choice

By default, only posts with a Featured Image will be shared, and posts without a Featured Image will not be shared.

When Featured Images are somehow not an option (because your theme doesn’t particularly like them, for instance), the Image Choice setting provides an alternative. When “First” is selected, WordPress will try to locate the first image inside your post’s content (and completely ignore any Featured Image) and share that instead.

Note: The plugin may not always find the first “in-post” image. For example, it doesn’t support externally hosted images.

It’s possible to fully override this behavior, too, using the share_on_pixelfed_image_path filter. Like, if you wanted the default behavior, yet have WordPress fall back onto the first image for posts that don’t have a Featured Image, you could write a callback function similar to this one:

add_filter( 'share_on_pixelfed_image_path', function( $file_path, $post_id ) {
  if ( has_post_thumbnail( $post_id ) ) {
    // Post has a Featured Image. Do nothing.
    return $file_path;
  }

  $pixelfed  = \Share_On_Pixelfed\Share_On_Pixelfed::get_instance()->get_post_handler();
  $alt_image = $pixelfed->find_first_image( $post_id );

  if ( ! empty( $alt_image ) ) {
    return $alt_image;
  }

  return $file_path;
}, 10, 2 );

Post Privacy

Currently, all statuses sent via this plugin are public. Unlisted or followers-only statuses may become an option later on.

Gutenberg

This plugin uses WordPress’ Meta Box API—supported by Gutenberg—to store per-post sharing settings, which makes it 100% compatible with the new block editor.

Links