How to Disable Ad Inserter Ads on Your WordPress REST API
Content
If you're using the WordPress REST API to power a mobile app or other service, you may have noticed that Ad Inserter is injecting ad codes into your API responses. This is a common occurrence because the plugin processes content through standard WordPress filter hooks, which are often used by the REST API to deliver post content.
Fortunately, this is a simple issue to resolve without needing any premium upgrades. The solution involves using the plugin's powerful URL blacklisting feature to prevent ads from being inserted on any REST API endpoints.
Why This Happens
Ad Inserter works by hooking into standard WordPress processes. By default, it may process content delivered via the wp-json/wp/v2/ REST API endpoints because they use the same content filters as your public website. This results in ad code appearing in your API responses, which is typically not the desired behavior for a clean data feed.
How to Disable Ads on the REST API
You can easily stop ads from appearing in your REST API output by adding a URL pattern to the block's blacklist settings. Here’s how to do it:
- Open your WordPress dashboard and navigate to Ad Inserter → Settings.
- Click to edit the specific block that is inserting ads where you don't want them.
- Locate the Blacklists tab for that block.
- In the URLs text area, enter the following pattern:
/wp-json/* - Save the block's settings.
This URL pattern acts as a wildcard, telling Ad Inserter to disable the block on any URL that begins with /wp-json/. This effectively prevents the block from loading on all standard WordPress REST API endpoints.
This method uses the free version of Ad Inserter and does not require any custom code or a Pro license. It's a straightforward and effective way to ensure your API data remains clean and ad-free.
Checking Your Work
After applying this setting, clear any active caching on your site (if you use a caching plugin) and then manually check your API endpoint in a browser or tool like Postman. You should no longer see the ad code in the response.
By using the URL blacklist feature, you have fine-grained control over exactly where your ads are displayed, ensuring they only appear for your website visitors and not in your application data.
Related Support Threads Support
-
Compatibility with adsense auto adshttps://wordpress.org/support/topic/compatibility-with-adsense-auto-ads/
-
Sticky adshttps://wordpress.org/support/topic/sticky-ads-6/
-
Ddisable caching for LiteSpeed Cachehttps://wordpress.org/support/topic/ddisable-caching-for-litespeed-cache/
-
SHow ads via REST APIhttps://wordpress.org/support/topic/show-ads-via-rest-api/
-
Insert Ads on Specific Postshttps://wordpress.org/support/topic/insert-ads-on-specific-posts/
-
Insert ads into meta menuhttps://wordpress.org/support/topic/insert-ads-into-meta-menu/
-
Make the disable cache work with WP Fastest Cache?https://wordpress.org/support/topic/make-the-disable-cache-work-with-wp-fastest-cache/
-
Disable ads in APIhttps://wordpress.org/support/topic/disable-ads-in-api/
-
normal and amp auto adshttps://wordpress.org/support/topic/normal-and-amp-auto-ads/
-
Are there any exceptions that need to be set when using a caching plugin?https://wordpress.org/support/topic/are-there-any-exceptions-that-need-to-be-set-when-using-a-caching-plugin/
-
How to include custom PHP functions?https://wordpress.org/support/topic/how-to-include-custom-php-functions/
-
predicts the beginning, middlehttps://wordpress.org/support/topic/predicts-the-beginning-middle/
-
Does this plugin Support Newspaper themehttps://wordpress.org/support/topic/does-this-plugin-support-newspaper-theme/
-
What is right way to put Adsense in Mobile only?https://wordpress.org/support/topic/what-is-right-way-to-put-adsense-in-mobile-only/
-
Do I need to make any additional settings for the LSCache plugin?https://wordpress.org/support/topic/do-i-need-to-make-any-additional-settings-for-the-lscache-plugin/
-
Put php functionhttps://wordpress.org/support/topic/put-php-function/
-
Duplicate contenthttps://wordpress.org/support/topic/duplicate-content-53/
-
Disable caching > add 2 other popular plugins to this listhttps://wordpress.org/support/topic/disable-caching-add-2-other-popular-plugins-to-this-list/
-
Newscard Themehttps://wordpress.org/support/topic/newscard-theme/