AdSense Plugin for WordPress

Manually insert placement code for the AdSense Plugin for WordPress

Use this article if you need to manually insert code for AdSense placements into the HTML of your WordPress site. This way you can add placements and manage them with the AdSense Plugin for WordPress even if the plugin did not detect every spot on your site where placements might be an option.

Normally, you can just review your site with the plugin and click placement markers in each place where you want to show ads. This is the easiest way to manage AdSense ads with our plugin. But if you don't see a placement marker in exactly the spot you need, you can add our placement code manually. After that, the plugin will show a marker in the corresponding location, and you will always have the option to insert a placement there with the plugin, or to remove or modify the placement. No additional code changes should be necessary.

Before you get started, keep this in mind:

  • Manual insertion is best for advanced users who feel comfortable working with things like HTML code and PHP files.

  • Our plugin is designed to help prevent you from adding placements where ads will have significant problems, such as not being clickable or viewable. However, it is ultimately the publisher’s responsibility to choose a functional ad layout, and to ensure compliance with all Google publisher policies.

Steps to manually insert placement code

This code adds an AdSense placement to your WordPress site. After you add the code, you can manage the placement with the AdSense Plugin for WordPress. Note that the ID must be unique: each time you add this snippet of code, use a different name for the ID.

<ins id="unique-ID"
style="display: none;"

1. Format your code

  • ID: Each time you add this code, use a different unique ID in place of unique-id. Use normal HTML for your ID, with no spaces. E.g., front-page-123, sidebar-ad-124, bottom-ad-125, etc.

  • Preview: You can preview your insertion with our plugin, just like the rest of your placements. However, you need to take extra steps if you wish to preview your insertion outside of our plugin, such while developing your theme and CSS locally. In that case, you must change display: none to display: block in each placeholder you want to preview. Just remember to change the style back to display: none before you update the file.

2. Insert your code

There are several ways you can add this placement code to your WordPress site. Here are two examples:

Add code to your PHP files

Edit your PHP files through your own system or through the WordPress theme code editor. See the WordPress Help Center to learn more about editing WordPress code.

  1. Select a PHP file to edit. This file should relate to a place where you want to show AdSense ads but could not find an option to do so with the AdSense Plugin for WordPress.

    In other words, find a PHP file that loads a part of your template where the AdSense Plugin for WordPress did not detect available ad space.

  2. Insert the AdSense placement code in the appropriate part of the PHP file. Remember to give the code a unique ID in place of unique-name.

  3. Update your files. Then check your inserted placement.


  • The WordPress theme code editor is only available if WordPress has file write access to your theme files. If the theme code editor is not available, you can modify PHP files using an FTP client.

  • Updates to your theme will override any manual edits your site's HTML code. You may want to consider creating a child theme to protect your edits, and then adding your placement to the child theme code. WordPress offers instructions here.

  • Keep in mind that if you don't see a placement marker in a particular spot, the reason may be that AdSense ads will not work properly in that location. The plugin only shows markers in places where you can display fully visible and clickable ads that won't overlap with your other content.

How PHP files affect your site

Every page on your site uses a particular template. The template helps determine its style and appearance. Your site theme is a set of templates.

Templates are based on PHP files. You can edit these PHP files on the "Edit Themes" page (if WordPress has file write access to your theme files). Some PHP files are just for simple design elements, like how a header looks on many of your templates. Other PHP files determine how an entire template looks. A PHP file may be used by multiple templates, so when you add placement code to a PHP file, you may see a new placement marker on multiple templates.

Add code with WordPress widgets

This option is best for adding placements to sidebars, footers, and other sections of your pages on the margins. See the WordPress Help Center for guidance on adding text widgets.

  1. Add the AdSense placement code to the body of your text widget. Remember to give the code a unique ID in place of unique-ID.

  2. Give the widget a title that indicates it is for your AdSense placements.

  3. Save. Then check your inserted placement.

3. Check your inserted placement

After you manually insert placement code, manage ads with the AdSense Plugin for WordPress to verify that your placement is now recognized by the plugin.

  • Find the marker: The plugin should show a placement marker in the spot that corresponds to your edited PHP file.

  • Check the settings: When you open the placement settings, the plugin will indicate that the placement is defined in your HTML code

  • Resolve issues: If you inserted code in an invalid place, the plugin will show you a gray marker in the spot where you added code for a placement. The reason is probably that an ad in this location would be unclickable, would not display correctly, or would overlap with your site content. Try inserting the code in a different location.

Help us improve this feature! We want to hear your feedback. Click here to send questions and comments.

Was this article helpful?