I am trying to pass content to the 'google_dfp_ad_slot' filter. Can this be done within a shortcode funcion?
/**
* Shortcode function to dynamically add google dfp ads to inline content and widgets
*
* [fopconnect_ad is_page="true" page="about"]
* {JS}googletag.defineSlot('/6111408/FOPC_All_LeaderBoard_728x90', [728, 90], 'div-gpt-ad-1398288352265-0').addService(googletag.pubads());{/JS}
* {HTML}<div id='div-gpt-ad-1342652501811-0' style='width:160px; height:600px;'><script type='text/javascript'>googletag.cmd.push(function() { googletag.display('div-gpt-ad-1342652501811-0'); });</script></div>{/HTML}
* [/fopconnect_ad]
*
* @param array $atts shortcode attributes
* @param string $content
* @return sting
*/
add_shortcode( 'fopconnect_ad', 'fopconnect_ad_func' );
function fopconnect_ad_func( $atts, $content ) {
extract( shortcode_atts( array(
'is_page' => false,
'page' => '' // can be title, slug, or id
), $atts ) );
preg_match("#\\{JS\\}(.*?)\\{/JS\\}#s", $content, $matches);
$js = ( !empty( $matches[1] ) ? $matches[1] : '' );
preg_match("#\\{HTML\\}(.*?)\\{/HTML\\}#s", $content, $matches);
$content = ( !empty( $matches[1] ) ? $matches[1] : '' );
if ( $is_page && is_page( explode(', ', $page) ) ) {
add_filter( 'google_dfp_ad_slot', function( $js ) { return $js; } );
}
if ( $is_page && is_page( explode(', ', $page) ) ) {
return $content;
}
}