New Plugin — Easier DoubleClick Ads for WordPress

This week we’re happy to announce a new WordPress plugin to make serving DoubleClick ads easy.

In the past we’ve used (and will continue to use) Automattic’s ad code manager to control ad tags. This plugin comes with a plethora of options, including support for different providers. While its fine for some users, for most of our applications it’s downright unwieldy.

We designed our plugin to be lighter-weight and to work out of the box with as little setup as possible. The minimum needed to start serving ads is to define your network code and place a widget in a sidebar. Then you set options for the DFP identifier and size of the ad spot and that’s all there is to it.

Responsive ads

It’s easy to serve different size creatives at different breakpoints. For example, in a leaderboard spot, it’s possible to add one widget to display 300x50 sized creatives on mobile and 728x90 size creative on tablets and desktops. Only one will be loaded and counted as viewed in DFP, depending on the breakpoint.


This plugin sends information about the page to DFP to make targeting specific sections and pages of a site easy.

  1. inURL: Target a piece of the page path. (eg. targeting the string /dvd would match, and
  2. URLIs: Target the entire page path. (eg. targeting the string /books will only match and not
  3. Domain: Target based on the domain. (eg. run different advertising on and
  4. Query: Target a ?query var. (eg. target the url with the targeting string movie:12)

See the documentation for more information on how to set these values up in DFP. We’ll be adding targeting criteria for post category, post type, template type and other criteria specific to WordPress in the future.


If you don’t maintain widget areas in your theme, you can hard code breakpoints and places ad units directly in your template files.

Defining breakpoints is simple. We suggest you do this for users in your theme’s functions.php since most users will not know pixel values for the theme's breakpoints.

function ad_setup() {

   global $DoubleClick;

   // Optionally define the network code directly in functions.php.
   // $DoubleClick->networkCode = "xxxxxxx";

   /* Define Breakpoints */
   $DoubleClick->register_breakpoint('phone', array('minWidth'=> 0,'maxWidth'=>720));
   $DoubleClick->register_breakpoint('tablet', array('minWidth'=>760,'maxWidth'=>1040));
   $DoubleClick->register_breakpoint('desktop', array('minWidth'=>1040,'maxWidth'=>1220));
   $DoubleClick->register_breakpoint('xl', array('minWidth'=>1220,'maxWidth'=>9999));


To place an ad in a given location, just call place_ad on the global $DoubleClick object.

   // Places a 728x90 leaderboard ad for all breakpoints but mobile.

That’s it. We’re excited to see how you use it! Download the plugin from Github here.

  • The plugin does not work! When you try to activate on WP it says Fatal Error has occurred on line 58

    • Sorry to hear you’re having trouble. We’re not seeing that error on our end so it might have something to do with a plugin or theme conflict with other stuff on your site. Do you have any other ad serving/management plugins active at the moment? You might want to try to deactivating those temporarily to see if this error still occurs on activation.

  • ted

    Hi Thanks for the plugin and the tut. Can you please clarify where I am to place this code if i want to show ads for single posts, as well as widget areas? Thanks in advance

    • Hi Ted – Are you saying that you’d want to show an ad in an area that is not a defined widget area? In the post body after the Nth paragraph or something like that, for example?

  • WassailAnyone?

    Hello, I’m very interested in this since I’ve spent a couple weeks trying to make ads responsive using sizeMapping, etc. The issue I have is that I have some ads in widgets that work fine and do their job, but another “developer” wants to put ads into a page editor module (called DIVI). Since these aren’t widgets, I’m having a hard time proceeding. Do you think your plugin will work with page editors like DIVI and Cornerstone?