Documentation » The “Syndication” Block

The “Syndication” Block

(Not to be confused with the Syndication Links plugin.)

The Syndication block is a “Theme” block. It shows so-called “syndication links,” links to “copies” of a post on social media or elsewhere.

Out of the box, the Syndication block supports links stored by the Share on Mastodon and Share on Pixelfed plugins. Other plugins’ syndication links can be added using the indieblocks_syndication_links filter:

add_filter( 'indieblocks_syndication_links', function( $urls, $post_id ) {
  // Maybe another plugin has stored a, for instance, Twitter URL.
  $twitter_url = get_post_meta( $post_id, '_share_on_twitter_url', true );

  if ( ! empty( $twitter_url ) ) {
    // Add it to the array.
    $urls['Twitter'] = $twitter_url;
  }

  return $urls;
} );

The Syndication block is a “dynamic” block, rendered server-side. Consequently, changes to syndication links are reflected immediately.

Should you use the Syndication Links plugin, links know to that plugin can be added as follows:

add_filter( 'indieblocks_syndication_links', function( $urls, $post_id ) {
  if ( class_exists( '\\Syn_Meta' ) && method_exists( '\\Syn_Meta', 'get_syndication_links_data' ) && method_exists( '\\Syn_Meta', 'extract_domain_name' ) ) {
    // Get all syndication links.
    $syn_links = \Syn_Meta::get_syndication_links_data( 'post', $post_id );

    if ( class_exists( '\\Syn_Link_Domain_Icon_Map' ) && method_exists( '\\Syn_Link_Domain_Icon_Map', 'url_to_name' ) ) {
      // Get each link's name, and add the link to our array.
      foreach ( $syn_links as $url ) {
        $name = ucwords( \Syn_Link_Domain_Icon_Map::url_to_name( $url ) );
        if ( 'Website' === $name ) {
          // Fall back to host name.
          $name = \Syn_Meta::extract_domain_name( $url );
        }

        $urls[ $name ] = $url;
      }
    } else {
      foreach ( $syn_links as $url ) {
        $urls[ ucwords( \Syn_Meta::extract_domain_name( $url ) ) ] = $url;
      }
    }
  }

  return $urls;
}, 10, 2 );