How to Insert Ad Shortcode in WordPress Posts

A client called me a few years back because a sponsor’s banner had disappeared from a post. Someone had redesigned the page, the sidebar got rebuilt, and the ad code went with it. The sponsor noticed before we did. That’s the kind of call you never want to get, and it’s why I lean on shortcodes for direct placements now. When you insert ad shortcode WordPress gives you a dependable spot for a campaign, right where readers actually are, and the inventory stays under your control.
Shortcodes really shine when an ad belongs to a specific moment in the reading experience. A newsletter promo after the intro. An affiliate offer sitting under a product comparison. A direct-sold banner in a sponsored series. Instead of pasting raw HTML or a network script into every post, you drop in a placement you can update from one place later.
What an ad shortcode actually solves
A shortcode is just a small WordPress command wrapped in square brackets. WordPress swaps it out for your ad creative or ad group when the page renders. The post stays readable in the editor, and all the advertising logic lives with your ad setup instead of being scattered across dozens of articles.
That separation matters more than people expect once a site grows. A campaign needs a new destination URL, or updated creative, or different dates, or a whole new advertiser. If the placement runs through a shortcode, you usually make that change once instead of editing every post the ad shows up in.
I also like how well shortcodes handle a mixed monetization setup. Self-hosted banners, direct sponsorships, affiliate promos, approved network creative… they all go in the same way. The options vary depending on which advertising plugin you use, but the goal is the same. Stop wrestling with ad code inside your content.
Set up the ad before you place it
Build the ad or ad group in your dashboard first, before you go copying anything. Add the creative, the destination URL, the campaign dates, and whatever tracking your workflow needs. If you’re using third-party network code, make sure it’s approved for that location and that the provider allows the kind of placement you have in mind.
Then decide whether the shortcode should be one fixed ad or a rotating group. A fixed placement makes sense when a contracted sponsor bought a specific position. A group works better when several advertisers share a slot, or when you want even rotation, or when you need a fallback after a campaign wraps up.
AdSanity generates shortcodes for both individual ads and ad groups, so you can schedule campaigns, rotate eligible creative, and track impressions and clicks without turning WordPress into a full ad server. Copy the shortcode your setup gives you instead of typing it from memory. I’ve fixed enough wrong-ID placements to know that typing it out never ends well.
How to insert ad shortcode in WordPress
Add it in the block editor
Open the post or page where you want the ad. Click the plus icon at the spot the placement belongs, search for the Shortcode block, and paste your shortcode in. Save or update, then load the published page and check that the ad shows up where you expected.
A generic example looks like this:
[adsanity id="107" align="alignleft" max_width="100"/]
Use it exactly as your plugin gives it to you. No extra paragraph tags, no smart quotes, no formatting wrapped around it. Those little edits are usually why WordPress doesn’t recognize the shortcode.
I think the block editor is the best option for editorial placements because writers and editors can see where the ad lives. They know a promo goes after a section break without having to read through a block of HTML or JavaScript to figure it out.
Use the Classic Editor or a page builder
In the Classic Editor, paste the shortcode into the Visual or Text editor wherever the ad should display. If it shows up as plain text on the front end, flip over to the Text editor and check that it didn’t get wrapped in some unexpected markup.
Most page builders have a dedicated Shortcode module or element. Use that instead of a plain text element when you can. Page builders love applying their own spacing and formatting rules, so always check the placement on desktop and mobile after you publish.
Add a shortcode in a theme template
Sometimes you need a placement in a template file, or a custom loop, or a carefully scoped theme hook. In PHP, WordPress can process a shortcode with do_shortcode
<?php echo do_shortcode('[adsanity id="107" align="alignleft" max_width="100"/]'); ?>
This is handy when a placement should appear consistently in a custom post layout. It’s not automatically the right call for every sitewide placement, though. Keep template changes in a child theme or a maintained custom plugin, and test after theme updates. Shortcodes are convenient, but code-level placement should still be deliberate and documented somewhere your future self can find it.
Place ads where they support the content
A shortcode gives you control. It’s not a reason to stuff an ad into every available gap. Start with placements that make sense for the page type and what the reader came for. An ad after the opening section tends to work in a long tutorial because the reader already knows the topic is relevant. A placement near the conclusion can suit a related tool or a newsletter sponsor. A banner above a comparison table might work for a clearly labeled sponsor, but it can also get in the way right before someone sees the information they came for.
Consistency helps a lot, especially on a bigger publication. If your editorial team always uses one placement after the first major section and another near the end, readers get a predictable experience and your advertisers get inventory that’s easier to describe and sell.
Keep ads away from buttons, navigation, download links, and form submissions. Accidental clicks make for a bad experience and can violate some network policies. Give each unit room to breathe, make it obvious what’s promotional and what’s editorial, and label sponsored placements when disclosure is required.
Protect performance and layout stability
The shortcode itself is light. The creative it loads might not be. Big image files, a pile of third-party scripts, and ads with no reserved dimensions will slow a page down or make content jump around as things load.
Use properly sized creative for each placement. If your ad system lets you set width and height or apply a CSS class to the container, reserve that space before the ad loads. It cuts down on layout shift and keeps readers from losing their place halfway through an article.
Be picky about third-party network tags. They can bring real demand, but every external script is another performance and privacy consideration. Test page speed with the actual placements live, not with empty containers. If a campaign is hurting performance, look at lighter creative, a smaller placement, or a self-hosted alternative.
Mobile deserves its own pass. An ad that looks great in a wide content column can overflow, shrink down to unreadable, or leave a weird gap on a phone. Pull up the published page at common breakpoints and make sure the placement plays nice with your theme’s responsive layout.
Schedule, measure, and test the placement
The nice thing about a managed shortcode is that the post can sit there untouched while campaigns change behind it. Schedule an ad to start and stop at the contracted time. When a campaign ends, rotate in another eligible ad or just leave the slot empty until you have something worth putting there. That beats leaving expired promos sitting in old posts for months.
Track impressions and clicks, but read those numbers with some context. A placement with fewer impressions can still be valuable if it lives on a high-intent page and sends qualified traffic. A highly visible unit with a weak click-through rate might need better creative, a more relevant offer, or a different spot in the article.
Change one variable at a time when you’re testing. Try new creative, then compare. Move the placement in a similar group of posts, then compare again. If you change the creative and the position and the audience and the dates all at once, your reporting won’t tell you a thing about what actually worked.
Fix common shortcode problems
If an ad isn’t showing up, run the simple checks before you start editing theme files or adding more code.
- If the shortcode shows up as text, make sure it’s in a Shortcode block, a shortcode module, or an editor area that actually processes shortcodes.
- If the space is empty, check that the ad is published, scheduled for today, and assigned to the right group or placement.
- If the wrong ad appears, verify the shortcode ID and confirm your rotation rules are doing what you think they’re doing.
- If recent changes aren’t showing, clear your site, host, and CDN caches. Cached pages will happily keep serving old creative long after you updated the campaign.
If the ad is there but looks wrong, open up your browser tools and take a look. A theme rule, an overly broad image style, or a container width can mess with the creative even when the shortcode is working perfectly.
The best ad placement is the one your team can maintain without second-guessing it. Put ads where they earn attention, make campaign changes from one dashboard, and keep the reader’s experience worthy of whatever brought them to the page in the first place.
Written by
Ready to get started?
Time to take control of your ads.
Find your perfect plan and go for it.
Popular Pro Add-Ons
Our Community
Join our mailing list to keep up to date on everything happening with AdSanity and Pixel Jar.
Note: Your email address will be added to our CRM and be used to receive emails from Pixel Jar. You can unsubscribe at any time.
Ready to Make Money With Your Site?
Get ads on your site in
60 minutes or less
with AdSanity.
With our 14-day money back guarantee, it’s easy to see if AdSanity is the right fit for you.


