adsenseを出力するphpを作る
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
cd <WordPressの子テーマのディレクトリ> mkdir -p template-parts/post/adsense.php cat - > template-parts/post/adsense.php --- <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <ins class="adsbygoogle" style="display:block; text-align:center;" data-ad-layout="in-article" data-ad-format="fluid" data-ad-client="略" data-ad-slot="略"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> --- |
single.phpを子テーマに持ってくる
1 |
cp ../twentyseventeen/single.php ./ |
single.phpを編集する
1 2 3 4 5 6 7 8 9 10 |
<?php /* Start the Loop */ while ( have_posts() ) : the_post(); get_template_part( 'template-parts/post/content', get_post_format() ); get_template_part( 'template-parts/post/adsense', get_post_format() ); // If comments are open or we have at least one comment, load up the comment template. if ( comments_open() || get_comments_number() ) : comments_template(); endif; |
※24行目の空白に「get_template_part( ‘template-parts/post/adsense’, get_post_format() );」を追加する