Sure, there is a dynamic filter on the query_args which is used to create every button. So the button name is part of the hook, but all the parameters for the filter are the same. For WhatsApp, you could do something like this:
add_filter( 'scriptlesssocialsharing_whatsapp_query_args', 'prefix_modify_whatsapp_text', 10, 4 );
/**
* Modify the text for the WhatsApp button.
*
* @param array $args
* @param string $button_name
* @param array $attributes
* @param array $setting
*
* @return mixed
*/
function prefix_modify_whatsapp_text( $args, $button_name, $attributes, $setting ) {
$args['text'] = 'Look at this article: ' . $args['text'];
return $args;
}
which should give you the modified text you want for the button. Hope that helps you get started.
Thread Starter
Idel
(@freetanga)
Thanks a lot Robin! 😀
And what about if you would like a shared text like:
“Please vote for TITLE at our contest — URL”
This one has custom text before and after the title.
Would that be possible?
Thanks again!
-
This reply was modified 6 years, 11 months ago by
Idel.
Sure, you can do whatever you want with the text. The original example uses only the query args parameter which is passed to the filter, but you can see that three other items are passed as well:
- button name: this will be whatsapp, twitter, etc.
- attributes: these attributes are specific to the post being shared, including the post ID, title, permalink, etc.
- setting: the plugin setting
To really experiment with it, I would suggest testing the filter locally and dumping out the attributes, for example, to see what you can do. So you could change the middle/modification line in the example above to something like:
$args['text'] = 'Please vote for ' . $attributes['title'] . ' at our contest — ' . $attributes['permalink'];
…note that would change the WhatsApp button text sitewide, which may not be appropriate. Using the attributes, however, you could run your filter only conditionally based on the post ID, for example.
Thread Starter
Idel
(@freetanga)
How well explained! You rock!
And yes, I used your code inside if ( ‘poll’ === get_post_type() ) …
Thank you very much! 😀
Thread Starter
Idel
(@freetanga)
Robin, is it possible to also customize the text that appears when sharing on Facebook?
In this case there is an image (the post thumbnail) a title and a subtitle.
Is there any way to customize those title and subtitle?
Thanks again 🙂
You can see what button parameters can be modified by looking at the individual button classes (see the Github repository), specifically the get_query_args method in each class. Facebook only takes the permalink as a query parameter; any modifications to the text/image/etc should be handled by changing the OpenGraph tags on the post in question. There are plugins which allow you to easily edit that data. Yoast SEO is one I have used to do this.
Thread Starter
Idel
(@freetanga)
I’m using Yoast SEO! I’m gonna check! Thank you! 🙂