这是indexloc提供的服务,不要输入任何密码
Skip to content

Ensure ad code doesn't run on 404 URLs #2784

@jamesozzie

Description

@jamesozzie

Bug Description

As per one users comments in the WordPress support forums AdSense policy dictates that ads should not be displayed on 404 URLs.

Consider adding a conditional statement to ensure ads don't appear on such URLs.

More insights on AdSense policy available here, with the below guidance included:
Publishers are not permitted to place ads on any non-content based pages like thank you, error, log in, or exit pages.


Do not alter or remove anything below. The following sections will be managed by moderators only.

Acceptance criteria

  • The AdSense snippet should not be included on any WordPress 404 URLs (is_404()), neither for AMP nor for non-AMP.
  • This should be unconditional and always take effect, there should be no setting for it.

Implementation Brief

  • Update the Modules\AdSense\Tag_Guard::can_activate method to return FALSE if is_404() returns TRUE.

Test Coverage

  • Update the Tests\Modules\AdSense\Tag_GuardTest class to make sure that Tag_Guard::can_activate method returns correct result for 404 pages.

Visual Regression Changes

  • N/A

QA Brief

  • Activate and connect AdSense module with use snippet setting enabled;
  • Go to the homepage or any page on the frontend and make sure that ad code is added to the page;
  • Go to a non-existing page (it should result in 404 status) and make sure that ad code is not added.

Changelog entry

  • Ensure that the AdSense snippet is not included on 404 pages in the frontend.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Module: AdSenseGoogle AdSense module related issuesP0High priorityType: BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions