Search by

automattic / jetpack-sharing-likes

jeherveautomattic

Sharing buttons and Like buttons for your posts.

Package info

github.com/Automattic/jetpack-sharing-likes

Type:jetpack-library

pkg:composer/automattic/jetpack-sharing-likes

Statistics

Installs: 225

Dependents: 1

Suggesters: 0

Stars: 0

v0.5.1 2026-10-28 19:56 UTC

This package is auto-updated.

Last update: 2026-10-30 19:47:53 UTC


README

Sharing buttons and Like buttons for your posts.

Today the package ships the wp-admin Settings > Sharing screen, under src/settings/, and the same settings over REST, under wpcom/v2/sharing-likes/, for the React version of the screen. A host plugin sets both up with one call, on every request rather than in an is_admin() branch, since REST requests are not admin requests, and Calypso's sidebar is built in one:

\Automattic\Jetpack\Sharing_Likes\Initializer::init();

Neither depends on a module being active: the screen and every section on it exist whichever modules are on, on any site that is Simple, connected, or in offline mode.

The same call hooks the Sharing Buttons and Like blocks into block themes' single post and page templates, before or after the post content, wherever the jetpack_sharing_buttons_auto_add and jetpack_likes_auto_add options ask for them and the legacy buttons are off. The settings REST route reads and saves them as sharing_buttons_auto_add and likes_auto_add; to try it without a screen:

wp option update jetpack_sharing_buttons_auto_add '["after_content"]' --format=json
wp option update jetpack_likes_auto_add '["before_content"]' --format=json

Single posts and pages get them by default. To add another post type's single views:

add_filter(
	'jetpack_sharing_likes_template_placement_post_types',
	function ( $post_types ) {
		$post_types[] = 'product';
		return $post_types;
	}
);

It also ships the per-post Likes and Sharing switches the block editor shows, as REST fields on every public post type. Initializer::init() leaves these out: each belongs to the feature that reads it, so call it wherever that feature loads (Likes or Comment Likes, and Sharing), outside any is_admin() branch:

\Automattic\Jetpack\Sharing_Likes\Post_Likes_Switch::init();
\Automattic\Jetpack\Sharing_Likes\Post_Sharing_Switch::init();

Calling either more than once is harmless.

React screen

Settings > Sharing renders a React version by default. To get the PHP screen back until it retires:

add_filter( 'rsm_jetpack_ui_modernization_sharing_likes', '__return_false' );

Add it before admin_menu runs, for example from a plugin or mu-plugin: the filter is read on admin_menu at priority 1, so adding it on admin_init silently does nothing.

Build it with pnpm run build (or jp build packages/sharing-likes).

How to install sharing-likes

Installation From Git Repo

Contribute

Get Help

Using this package in your WordPress plugin

If you plan on using this package in your WordPress plugin, we would recommend that you use Jetpack Autoloader as your autoloader. This will allow for maximum interoperability with other plugins that use this package as well.

Security

Need to report a security vulnerability? Go to https://automattic.com/security/ or directly to our security bug bounty site https://hackerone.com/automattic.

License

sharing-likes is licensed under GNU General Public License v2 (or later)