我正在尝试将内容传递到“google\\u dfp\\u ad\\u slot”过滤器。这可以在短码函数中完成吗?
/**
* 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;
}
}