Skip to content

Instantly share code, notes, and snippets.

@robincornett
Created April 23, 2019 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robincornett/99c241171708a24a7b895b8607945cd0 to your computer and use it in GitHub Desktop.
Save robincornett/99c241171708a24a7b895b8607945cd0 to your computer and use it in GitHub Desktop.
Add a hashtag to all Twitter sharing buttons on a site (in Scriptless 3.0.0)
<?php
add_filter( 'scriptlesssocialsharing_twitter_query_args', 'prefix_add_twitter_hashtag_scriptless' );
/**
* Add a hashtag to every Twitter button on a site.
* Requires Scriptless Social Sharing 3.0.0
*
* @param $query_args
* @return mixed
*/
function prefix_add_twitter_hashtag_scriptless( $query_args ) {
$query_args['text'] .= rawurlencode( ' #hashtag' );
return $query_args;
}
@robincornett
Copy link
Author

robincornett commented Apr 23, 2019

Actually, this could be done in the current version of Scriptless with the scriptlesssocialsharing_twitter_text filter. Example:

add_filter( 'scriptlesssocialsharing_twitter_text', 'prefix_add_twitter_hashtag_scriptless' );
/**
 * Add a hashtag to every Twitter button on a site.
 *
 * @param $text
 * @return mixed
 */
function prefix_add_twitter_hashtag_scriptless( $text ) {
	return $text .= rawurlencode( ' #hashtag' );
}

Actually, this filter is also added in 3.0, so it's not available yet either. My apologies for the error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment