Filter the sharing title.
Parameters
- $post->post_title
string
Post Title.
- $post_id
int
Post ID.
- $this->id
int
Sharing ID.
Changelog
- Introduced in Jetpack 2.8.0
How to use this hook
Notes
You can use that filter to customize the output of some of the sharing buttons. In the example below, we’ll usesharing_title
to automatically add hashtags to the twitter sharing button, based on the tags added to the post:
function jeherve_custom_sharing_title() { $post = get_post(); if ( empty( $post ) ) { return; } else { // Create sharing title $sharing_title = get_the_title( $post->ID ); // Get the tags $post_tags = get_the_tags( $post->ID ); if ( ! empty( $post_tags ) ) { // Create list of tags with hashtags in front of them $hash_tags = ''; foreach( $post_tags as $tag ) { $hash_tags .= ' #' . $tag->name; } // Add tags to the title $sharing_title .= $hash_tags; } return $sharing_title; } } add_filter( 'sharing_title', 'jeherve_custom_sharing_title', 10, 3 );