• Skip to primary navigation
  • Skip to main content
Sal Ferrarello
  • About Sal Ferrarello
  • Speaking
  • Connect
    Mastodon GitHub Twitter (inactive)
You are here: Home / Dev Tips / UTM parameters with Scriptless Social Sharing
UTM Parameters.

UTM parameters with Scriptless Social Sharing

Last updated on July 8, 2018 by Sal Ferrarello

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 );
}
Sal Ferrarello
Sal Ferrarello (@salcode)
Sal is a PHP developer with a focus on the WordPress platform. He is a conference speaker with a background including Piano Player, Radio DJ, Magician/Juggler, Beach Photographer, and High School Math Teacher. Sal can be found professionally at WebDevStudios, where he works as a senior backend engineer.

Share this post:

Share on TwitterShare on FacebookShare on LinkedInShare on EmailShare on Reddit

Filed Under: Dev Tips, marketing, Programming, Solution Tagged With: seo, WordPress Filter

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Copyright © 2023 · Bootstrap4 Genesis on Genesis Framework · WordPress · Log in