Created
March 30, 2013 21:26
-
-
Save woodroots/5278411 to your computer and use it in GitHub Desktop.
本文中の1つ目の見出しの上に広告を挿入する
This file contains 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
function content_ad($content){ | |
//個別記事ページかどうか判定 | |
if(is_single()){ | |
//ヒアドキュメントで広告用コードの定義 | |
$ad = <<< EOF | |
<div class="module"> | |
<script type="text/javascript"><!-- | |
google_ad_client = "ca-pub-0596916800718129"; | |
/* wrbt */ | |
google_ad_slot = "9046521069"; | |
google_ad_width = 336; | |
google_ad_height = 280; | |
//--> | |
</script> | |
<script type="text/javascript" | |
src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> | |
</script> | |
</div> | |
EOF; | |
//第4引数に何回置換するかを指定することができる。 | |
$content = preg_replace('/(<h3>|<h4>)/',"$ad$1",$content,1); | |
return $content; | |
} | |
return $content; | |
} | |
add_filter('the_content','content_ad'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment