Jeremy Herve Avatar

That’s me. And my blog. In English and in French.


Jetpack: move Jetpack Ads further down in a post

You’ve probably heard about Jetpack’s new Ads module: it allows you to insert ads in your posts, in your sidebar, and in the header of your WordPress site without having to worry about finding the right ad network, managing ad inventory, or worrying about the quality of the ads. It’s available to Jetpack Premium and Professional users.

To use the feature, all you have to do is to click on the toggle under the Jetpack menu in your dashboard. Jetpack takes care of the rest.

However, sometimes you may not be happy with the default placement of the in-post ads: they appear right below the post content. That’s great, but sometimes you may be using other plugins to insert elements in there, like sharing buttons, related posts, subscription forms, …

The code snippet below will allow you to move the ad box exactly where you want it to appear.

/**
 * Move Jetpack ads further down, below elements added by other plugins.
 *
 * @see https://wordpress.org/support/topic/how-to-reposition-ads/
 *
 * @param string $content Post content.
 */
function jeherve_ads_down( $content ) {
    /**
    * Disable default ads that get added below the content.
    *
    * @see https://developer.jetpack.com/hooks/wordads_inpost_disable/
    */
    add_filter( 'wordads_inpost_disable', '__return_true' );

    // Insert our custom ad.
    if ( class_exists( 'WordAds' ) ) {
        $custom_ads = new WordAds();
        return $content . $custom_ads->get_ad( 'belowpost' );
    }

    return $content;
}
/**
* I used priority 99 below.
* To move the ads higher, pick a higher priority.
*/
add_filter( 'the_content', 'jeherve_ads_down', 99 );

You can add that code to a functionality plugin like this one.

You could also use the same method to insert the ads anywhere on your site, by hooking into a different filter!

Not familiar with Jetpack Ads, né WordAds? Check this video!

Reactions on the Fediverse and on the ATmosphere

Continuez votre lecture / Keep reading

Discover more posts about or look at some of the posts suggested below.

Jeremy Herve
Jeremy Herve

WordPress, TV Series, music, kids, and board games. I think that’s probably the best way to define me in a few words. 🙂

I work at Automattic where I lead a team building tools for bloggers and creators. I talk a lot about WordPress things, but also about all things open source in general.

I post in English and in French.

I live in Brittany, France, so you’ll also find me sharing pictures from our beautiful region from time to time.

1,241 posts
194 followers