前提・実現したいこと
WPでアドセンス広告をh2の前に貼るため以下のコードをfunctions.phpに貼りましたが
タイトルの通りエラーが出ます。
発生している問題・エラーメッセージ
syntax error, unexpected end of file
該当のソースコード
function add_ad_before_h2($the_content) {
$ad = <<< EOF
//広告//
<br>
EOF;
if ( is_single() ) {
$h2 = '/^<h2.*?>.+?</h2>$/im';
if ( preg_match_all( $h2, $the_content, $h2s )) {
if ( $h2s[0] ) {
if ( $h2s[0][1] ) {
$the_content = str_replace($h2s[0][1], $ad.$h2s[0][1], $the_content);
}
if ( $h2s[0][2] ) {
$the_content = str_replace($h2s[0][2], $ad.$h2s[0][2], $the_content);
}
}
}
return $the_content;
}
add_filter('the_content','add_ad_before_h2');
### 試したこと 最後の1行がエラーと出ます。 add_filter('the_content','add_ad_before_h2'); 半角や空白などもないと思うのですが、どこが問題でしょうか? ### 補足情報(FW/ツールのバージョンなど) よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー