WordPress Twentyseventeen 子テーマにGoogle Adsenseを差し込む


adsenseを出力するphpを作る

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を子テーマに持ってくる

cp ../twentyseventeen/single.php ./

single.phpを編集する

            <?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() );」を追加する