Skip to content

Instantly share code, notes, and snippets.

@derekcavaliero
Created September 13, 2017 18:39
Show Gist options
  • Save derekcavaliero/2dafe10e50bd2aaa8f3aeb810c60e6c7 to your computer and use it in GitHub Desktop.
Save derekcavaliero/2dafe10e50bd2aaa8f3aeb810c60e6c7 to your computer and use it in GitHub Desktop.
WordPress Filter - Append permalink to Pardot iframe src attribute
<?php
/**
* Finds all Pardot form iframes and appends a ?embedded_on= query parameter to the source.
* Very useful for fixing the crappy issues with pardot tracking...
*/
add_filter( 'the_content', 'pardot_iframe_src_filter', 99, 1 );
function pardot_iframe_src_filter( $content ) {
global $post;
$permalink_path = wp_make_link_relative( get_permalink( $post->ID ) );
// Replace: your\.pardotdomain\.com with the TLD you use for serving pardot forms.
$content = preg_replace('#\<iframe(.*?)\ssrc\=\"http(s)?:\/\/(your\.pardotdomain\.com|go\.pardot\.com)(.*?)\"(.*?)\>#i',
'<iframe$1 src="http$2://$3$4?embedded_on=' . urlencode( $permalink_path ) . '"$5>', $content);
return $content;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment