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/

Newer versions of Pixelfed will turn that URL into a clickable link, so no worries there.

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 );

Posting From Mobile Apps

Even supported (per their Post Type) posts won’t be shared if not posted through WP Admin, as the “Share on Pixelfed” checkbox value will not have been saved.

To work around this, e.g., for posts created through a third-party app, there’s a share_on_pixelfed_enabled filter:

// Always share supported Post Types.
add_filter( 'share_on_pixelfed_enabled', '__return_true' );

Make Sharing Opt-In

Somewhat related: Share on Pixelfed’s checkbox is enabled by default. Adding this to, e.g., your theme’s functions.php changes that:

add_filter( 'share_on_pixelfed_optin', '__return_true' );

Post Privacy

It’s possible to override the arguments sent to Pixelfed’s API, and modify who can see your posts. To do: include how!

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