Skip to content

Conversation

peterwilsoncc
Copy link
Contributor

Modifies the conditions under which IndexNow is pinged.

Why

  1. To ensure that newly 404ing URLs are sent to hosts to encourage them to de-index them.
    In the event someone has accidentally published a page and then unpublished it, it's likely they wish to have the URL removed from search engines asap.
  2. Prevent double pings for posts on sites that use legacy meta boxes (a very popular SEO plugin still uses them so it's not uncommon)

How

Replaces the check for 'publish' !== $new_status with a check whether the old and new post statuses are publicly viewable.

If both are not viewable no ping takes place as the URL will be an existing 404 response.

If one is viewable but the other is not, a ping takes place as the page has either being updated or unpublished.

As sites can have custom public post statuses, I've removed the hard coded publish status check as is_post_status_viewable() will cover a wider range of statuses, including publish.

No ping takes place for non-viewable post types as the it shouldn't change without developer intervention, at which point they are responsible for the SEO impacts of the change.

For item 2: Bypass pinging if '1' == $_GET['meta-box-loader']

Fixes #158.

Signed-off-by: Peter Wilson <git-commit-by@peterwilson.cc>
@peterwilsoncc peterwilsoncc force-pushed the fix/ping-index-now-new-404s branch from d14f180 to a701299 Compare July 12, 2025 02:06
Copy link
Member

@rmccue rmccue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me; would appreciate @jdevalk's eyes on as well.

Copy link
Member

@jdevalk jdevalk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

For reference, as I did just verify, the FAQ on https://www.indexnow.org/faq explicitly states that pinging with newly 404ing URLs to get them removed is fine, so this is a solid improvement.

Signed-off-by: Ryan McCue <me@ryanmccue.info>
@peterwilsoncc
Copy link
Contributor Author

I've checked the PHPCS failures, they're happening in an unrelated file.

FWIW, in the implementation for my site (very heavily based on this code), I also removed the revision and autosave check to allow is_post_status_viewable() handle the bypass but I figured it was safer to leave them in place for this code.

@afragen afragen merged commit 966c829 into fairpm:main Jul 13, 2025
45 of 46 checks passed
@peterwilsoncc peterwilsoncc deleted the fix/ping-index-now-new-404s branch July 14, 2025 03:45
@peterwilsoncc
Copy link
Contributor Author

@rmccue @jdevalk @afragen

I got this wrong. The newly 404ing URLs don't use the correct permalink as it returns the plain version, ie example.com/?p=1234.

I'm figuring it all out in a plugin to account for various use cases. Including tests. https://github.com/peterwilsoncc/no-fuss-indexnow

peterwilsoncc added a commit to peterwilsoncc/fair-plugin that referenced this pull request Sep 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ping IndexNow when old status is published.
4 participants