Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bluesky button #38

Open
aharonium opened this issue Nov 18, 2024 · 0 comments
Open

Bluesky button #38

aharonium opened this issue Nov 18, 2024 · 0 comments

Comments

@aharonium
Copy link

aharonium commented Nov 18, 2024

I wanted to add a Bluesky button to pass along posts from my Wordpress site. There's some Bluesky documentation on what's needed here. Using the procedures in the Scriptless Social Sharing documentation I was able to produce a function that works. (The following code is operating now on my site.) For folk looking to adopt, adapt, or improve on this, I'm adding the following note.

The custom URL generated adds %20 in place of spaces in the post Title as well as between the Title and the post URL. Bluesky recognizes the URL as a URL but it doesn't seem to automatically separate the Title from the post URL in the Bluesky post without some manual typing. (I added a report on this in Bluesky's github discussion board here.) I added two spaces %20%20 between the post Title and post URL by creating a custom text, and I'm using a custom permalink to avoid transgressing the 300 character limit on posts with moderately long titles and long permalinks. To get the custom text to work, I had to increase the priority of my filter to override some other code that was resisting my filter under normal priority.

Here is the function I wrote and would love if this would be improved to the point that it might be integrated into Scriptless Social Sharing.

// Add Bluesky button to Scriptless Social Sharing plugin
add_filter( 'scriptlesssocialsharing_register', function( $buttons ) {
$buttons['bluesky'] = array(
'label' => 'Bluesky',
'url_base' => 'https://bsky.app/intent/compose',
'args' => array(
'query_args' => array(
'text' => '%%custom_text%%', // %% placeholders for the text to go into the Bluesky post.
),
'color' => '#3333cc', // Optional: Custom button color.
'icon' => '', // Optional: SVG icon for Bluesky.
),
);
return $buttons;
}, 20 ); // Higher priority ensures it overrides other filters.

add_filter( 'scriptlesssocialsharing_bluesky_query_args', function( $query_args, $id, $attributes, $setting ) {
global $post;
if ( ! $post instanceof WP_Post ) {
return $query_args;
}
$post_title = get_the_title( $post->ID );
$shortlink = site_url( '?p=' . $post->ID );
// Adding two spaces to separate the post Title from the URL.
$query_args['text'] = $post_title . ' ' . $shortlink;
return $query_args;
}, 20, 4 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant