こんにちわ
いつも楽しく使わせて頂いております。
以前ブログで拝見したコードを改変して下記のようにampパラメータで場合分けして広告を貼っています。
$the_contentの代わりに、関連記事を取得してその下に広告コードを付け加えることはできるのでしょうか。
もしくは’get_template_part_related-entries’をフックして何か書き加えたる必要があるでしょうか。
簡単な何かヒントでも頂ければ幸いです。
function add_ad_before_h2_for_3times($the_content) {
if ( is_single() ) { //投稿ページ(PC)
$h2 = ‘/^<h2.*?>.+?<\/h2>$/im’;//H2見出しのパターン
if(isset($_GET[‘amp’]) ) {
//広告をはる
$ad.bot = “”;
$the_content = $the_content.$ad_bot;
}
}
return $the_content;
}add_filter(‘the_content’,’add_ad_before_h2_for_3times’);