Back to Community

How to Add Google AdSense Ads to Your Twenty Sixteen Theme

10 threads Sep 16, 2025 ThemeTwenty sixteen

Content

Many WordPress users choose the clean, responsive Twenty Sixteen theme for their websites. A common goal for these site owners is to monetize their content by integrating Google AdSense advertisements. However, as a default theme, Twenty Sixteen isn't pre-configured with specific ad placement areas, leading to confusion about how and where to insert ad code.

Based on common community questions, users typically want to place ads in these key locations:

  • Between posts on the homepage and archive pages (like categories).
  • Within individual posts, directly under the article title.
  • In the sidebar widget area.
  • As floating ads in the left and right margins of the page.

Modifying a theme directly can be risky, as your changes will be overwritten the next time the theme updates. The safest and most recommended method is to use a child theme. This allows you to make all necessary customizations without affecting the parent Twenty Sixteen theme. If you haven't set up a child theme yet, the WordPress.org handbook has an excellent guide on creating child themes.

Solution 1: Inserting Ads Between Posts on Homepage and Category Pages

This requires modifying the main loop. You can use the `the_post` action hook to inject ad code after a specific number of posts.

Step 1: Add the following code to your child theme's functions.php file.

function twentysixteen_insert_ads_between_posts( $content ) {
    if ( is_home() || is_archive() ) {
        static $post_count = 0;
        $post_count++;
        // Insert ad after every 3rd post. Change '3' to your preferred frequency.
        if ( $post_count % 3 === 0 ) {
            $ad_code = '<div class="custom-ad">'
                     . '<!-- Paste your Google AdSense code here -->'
                     . '</div>';
            $content .= $ad_code;
        }
    }
    return $content;
}
add_filter( 'the_content', 'twentysixteen_insert_ads_between_posts' );

Step 2: You might need to add some CSS to style the ad container and ensure it displays correctly. Add CSS like the following to your child theme's style.css file.

.custom-ad {
    margin: 40px 0;
    text-align: center;
}

Solution 2: Placing an Ad Under the Title on Single Posts

This is one of the most requested placements. You can achieve it by hooking into the theme's template.

Step 1: Add this code to your child theme's functions.php file. It will insert the ad directly after the post title on single post pages only.

function twentysixteen_ad_after_title( $title ) {
    if ( is_single() && in_the_loop() ) {
        $ad_code = '<div class="post-title-ad">'
                 . '<!-- Paste your Google AdSense code here -->'
                 . '</div>';
        return $title . $ad_code;
    }
    return $title;
}
add_filter( 'the_title', 'twentysixteen_ad_after_title' );

Step 2: Add corresponding CSS to your style.css to control the ad's appearance.

.post-title-ad {
    margin-bottom: 30px;
    display: block;
}

Solution 3: Using the Built-in Widget Area for Sidebar Ads

This is the simplest method and requires no code. Twenty Sixteen includes a sidebar widget area that is perfect for advertisements.

Navigate to Appearance > Widgets in your WordPress dashboard. Locate the "Sidebar" widget area. Add a "Custom HTML" widget to this area and paste your AdSense code inside it. The ad will automatically appear on all pages where the sidebar is displayed.

Solution 4: Addressing Floating Left/Right Ads and Layout Issues

Some users report layout problems, like the sidebar moving to the bottom, when adding custom code. This is almost always caused by HTML markup errors or CSS conflicts.

  • Check Your Code: Ensure the AdSense code you are inserting is valid and complete. A missing closing </div> tag can break the entire page layout.
  • Use CSS Carefully: When adding floating ads, use precise CSS. For example, to add a fixed floating ad on the right side, you would need CSS that positions it absolutely without disrupting the main content flow.
.floating-right-ad {
    position: fixed;
    right: 10px;
    top: 50%;
    z-index: 100;
}
/* Use a media query to hide the ad on small screens to avoid layout issues */
@media (max-width: 1000px) {
    .floating-right-ad {
        display: none;
    }
}

Important Note: Always review and comply with Google AdSense Program Policies regarding ad placement, number of ads per page, and responsive behavior. Invalid traffic or improper placement can lead to account suspension.

By following these methods, you can successfully integrate AdSense into your Twenty Sixteen theme. Remember, using a child theme protects your modifications from being lost during updates. For more complex layout shifts, carefully inspect your browser's console for errors and validate your HTML.