You may have noticed that we’ve tweaked how we display our adsense ads. We wanted some small text-only ads near the bottom of each article, which would be added automatically. This took a little bit of tinkering, but eventually we developed a solution which works well and doesn’t seem to knock page processing times much. Simply add the following code to your theme’s functions.php (あなたのAdSenseのIDを変更するためには、得ることはありません)
Updated 12-Nov-2017 as the code wasn’t working correctly as previously displayed. 私も追加しました 2 other functions that I use, one to insert adverts via shortcode, and another to add an advert where the more is removed when a post is shown in full
/************************************************************************\
* を挿入するためのAdsenseのショートコード 2 どこでもショート経由で小さな広告 *
\************************************************************************/
関数Google_Adsense( $ATTS, $コンテンツ= nullを ) {
return '<DIVクラス="a" スタイル="テキストを整列: センター;"><DIVのID ="グーグル-1"></DIV><Pスタイル="明確な: 両方"></P></DIV>';
}
add_shortcode('google_adsense', 'Google_Adsense');
/******************************************\
* ショー 2 より多くのタグに小さなAdSense広告 *
\******************************************/
ADD_FILTER('the_content', 'adsense_added_at_more_tag');
// この機能は、AdSenseのコードを使用してより多くのタグを置き換えます.
関数adsense_added_at_more_tag($テキスト) {
もし( is_single() ) :
$ads_text = '<DIVのID ="グーグル" クラス="a" スタイル="テキストを整列: センター;"><DIVのID ="グーグル-1"></DIV><Pスタイル="明確な: 両方"></P></DIV>';
$POS1 =長期間存在($テキスト, '<スパンID ="more-');
//"
もし($POS1 === FALSE) $テキスト= $ ads_text . $テキスト;
ほかに
{
$POS2 = strpos($テキスト, '</スパン>', $POS1);
$テキスト1 = SUBSTR($テキスト, 0, $POS1);
$テキスト2 = SUBSTR($テキスト, $POS2 + 7);
$テキスト= $テキスト1 . $ads_text . $テキスト2;
}
ENDIF;
リターン$テキスト;
}
/*******************************************************\
* 最後の段落の上に単一の大規模なAdSense広告を表示します *
\*******************************************************/
ADD_FILTER('the_content', 'gads_added_above_last_para');
関数gads_added_above_last_para($ytext) {
もし( is_single() ) :
$yads_text = '<DIVクラス="a" スタイル="テキストを整列: センター;"><DIVのID ="グーグル-2"></DIV><Pスタイル="明確な: 両方"></P></DIV>';
もし($ypos1 =のstrrpos($ytext, '</P>')){
$ytext1 = SUBSTR($ytext, 0, ($ypos1 + 4));
$ytext2 = SUBSTR($ytext, ($ypos1 + 4));
$ytext = $ ytext1 . $yads_text . $ytext2;
}
ENDIF;
リターンの$ ytext;
} 
I don’t know but your code was not working in my case. そう, I replaced it with other code. If anyone else is facing the same problem, あなたは以下のコードを使用することができます.
function insert_ad_block( $テキスト ) {
もし ( is_single() ) :
$ads_text =「ここでは私の広告コード」;
$split_by =「 nを」;
$insert_after = 2; //段落の数
// 段落の配列を作ります
$paragraphs = explode( $split_by, $テキスト);
// if array elements are less than $insert_after set the insert point at the end
$LEN =数( $paragraphs );
もし ( $のみ < $insert_after ) $insert_after = $ LEN;
// insert $ads_text into the array at the specified point
array_splice( $paragraphs, $insert_after, 0, $ads_text );
// 出力のためのアレイと、ビルド文字列をループ
foreachの( $paragraphs as $paragraph ) {
$new_text .= $paragraph;
}
リターンの$ NEW_TEXT;
ENDIF;
リターン$テキスト;
}
ADD_FILTER(‘the_content’, ‘insert_ad_block’);
後に、この発言をする方法はありますか 2ND 段落の代わりに、最後の1の前に?
絶対温度-lutely. あなただけの、わずかなコードを微調整する必要があります. 私が使用しています
strrposの最後の発生·renceを見つけている<p>あなたは第二発生 - renceを検索する場合
<p>ラインを置き換える 13 で上記のコードから...偉大な仕事の男. どうもありがとう. Do you have any idea how to place a horizontal line above and below the ad unit?
確か. のカップルを追加 <HR />さん - 1 at the start of the value of $ads_text and the other at the end.
E.g. 交換する
とともに