Created
January 22, 2019 16:45
-
-
Save nleush/ec9deeb5161e68103aa5043027b87586 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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