Skip to content

Instantly share code, notes, and snippets.

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 nleush/ec9deeb5161e68103aa5043027b87586 to your computer and use it in GitHub Desktop.
Save nleush/ec9deeb5161e68103aa5043027b87586 to your computer and use it in GitHub Desktop.
# Bypass oEmbed sandbox for store links, add UTM params into the summary card
add_filter( 'pre_oembed_result', 'add_utm_params_to_barstool_store', PHP_INT_MAX, 3 );
function add_utm_params_to_barstool_store ( $result, $url, $args ) {
if ( strpos($url, 'https://store.barstoolsports.com') !== false && strpos($url, 'utm_') === false ) {
$api_key = trim( get_site_option( 'iframely_api_key' ) );
$link = $url;
$link = add_query_arg( array(
'utm_source' => 'barstoolsports',
'utm_medium' => 'referral',
'utm_content' => 'blog',
'utm_term' => get_post_field( 'post_name', get_post() ),
'utm_campaign' => get_post_field( 'post_name', get_post() )
), $link) ;
$src = 'https://if-cdn.com/api/iframe';
$src = add_query_arg( array(
'url' => urlencode ( $link ),
'key' => md5($api_key)
), $src );
$html = "<div class='iframely-embed'><div class='iframely-responsive' style='height: 168px; padding-bottom: 0;'><a href='$link' data-iframely-url='$src'></a></div></div><script async src='https://if-cdn.com/embed.js' charset='utf-8'></script>";
return $html;
} else {
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment