fix(adsense): Disable Auto Ads when disable_auto_ads is enabled

- Add enable_page_level_ads: false to prevent Google from
  automatically inserting ads in unwanted locations
- This prevents ads from appearing inside table cells and
  other inappropriate places

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
FrankZamora
2025-11-27 15:29:16 -06:00
parent 99cde7c3d6
commit 2acce34d9e

View File

@@ -157,6 +157,9 @@ function roi_should_disable_auto_ads(): bool
/** /**
* Carga el script principal de AdSense * Carga el script principal de AdSense
*
* IMPORTANTE: Si disable_auto_ads está activo, se añade código para
* deshabilitar Auto Ads (page-level ads) de Google.
*/ */
function roi_enqueue_adsense_script(): void function roi_enqueue_adsense_script(): void
{ {
@@ -180,13 +183,25 @@ function roi_enqueue_adsense_script(): void
} }
$delayEnabled = ($settings['forms']['delay_enabled'] ?? true) === true; $delayEnabled = ($settings['forms']['delay_enabled'] ?? true) === true;
$disableAutoAds = ($settings['visibility']['disable_auto_ads'] ?? true) === true;
// Script principal de AdSense
if ($delayEnabled) { if ($delayEnabled) {
echo '<script type="text/plain" data-adsense-script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=' . esc_attr($publisherId) . '" crossorigin="anonymous"></script>' . "\n"; echo '<script type="text/plain" data-adsense-script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=' . esc_attr($publisherId) . '" crossorigin="anonymous"></script>' . "\n";
} else { } else {
echo '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=' . esc_attr($publisherId) . '" crossorigin="anonymous"></script>' . "\n"; echo '<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=' . esc_attr($publisherId) . '" crossorigin="anonymous"></script>' . "\n";
} }
// Deshabilitar Auto Ads (page-level ads) si está configurado
if ($disableAutoAds) {
echo '<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "' . esc_js($publisherId) . '",
enable_page_level_ads: false
});
</script>' . "\n";
}
} catch (\Throwable $e) { } catch (\Throwable $e) {
if (defined('WP_DEBUG') && WP_DEBUG) { if (defined('WP_DEBUG') && WP_DEBUG) {
error_log('ROI AdSense: ' . $e->getMessage()); error_log('ROI AdSense: ' . $e->getMessage());