When it comes to adding social sharing buttons (e.g. “Share on Facebook”), I’m a big fan of Scriptless Social Sharing by Robin Cornett.
UTM Parameters
I’m no marketing expert but I am familiar with the benefits of using UTM parameters in tracking how your links are shared.
Adding UTM Parameters to Scriptless Social Sharing Links
My goal is to add UTM parameters to the links shared by the social media buttons on my site. Scriptless Social Sharing lets me do this with the filter scriptlesssocialsharing_get_permalink
.
Here is the code I’m using on my site to add values for utm_source
and utm_medium
.
/**
* Add utm parameters to scriptless social sharing links.
*/
add_filter( 'scriptlesssocialsharing_get_permalink', 'fe_sss_get_permalink_utm', 10, 3 );
function fe_sss_get_permalink_utm( $url, $button_name, $attributes ) {
return add_query_arg( array(
'utm_source' => 'sfcom',
'utm_medium' => esc_attr( $button_name ),
), $url );
}
Leave a Reply