=== Heading Anchor Check ===
Tags: anchors, headings, block editor
Requires at least: 6.6
Tested up to: 7.1
Stable tag: 0.2.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Find saved heading anchors that are missing or point to multiple elements in your edits before updating a post or page.

== Description ==

A reader may have bookmarked a section such as /guide/#delivery even if no other page on your site links to it. When revising that guide in the block editor, open the settings sidebar, expand Heading anchor check, and select Compare heading targets before saving. The panel lists missing targets and warns when a saved heading anchor matches more than one element in the edited post. It does not change the post.

For example, if the saved heading used delivery and you changed its HTML anchor to shipping, look for #delivery in the results. To keep the old link, select the intended block, open Advanced, and restore delivery in HTML anchor (without the #). Compare again before saving.

The check reads explicit heading IDs in the saved post body and looks for matching targets in the edited body. A match only establishes that the target exists; check that it still leads to the intended section. Theme-generated headings, anchors added when a shortcode runs, and links from other sites are outside this comparison. Saving an update changes the baseline for the next comparison.

= Try it with a fictional post =

[Open the free demo launcher](https://yenplant-heading-anchor-check.compassionatepenny32.chatgpt.site) and follow its link to the official WordPress Playground. It opens a temporary WordPress environment with this plugin and a fictional post; you do not need to connect your own site or provide real content.

In the demo's block editor, compare the saved heading targets, change the heading's HTML anchor from delivery to shipping, then compare again before saving. Restore delivery and compare once more. This demonstrates a missing target and its restoration, not a check of incoming links. Playground downloads its runtime, so an internet connection is needed. The demo launcher is provided by yenplant; the plugin is not represented as approved or listed by WordPress.org.

== Installation ==

1. On a test WordPress site where you can install plugins, open Plugins > Add New Plugin > Upload Plugin. Choose heading-anchor-check.zip, then install and activate Heading Anchor Check.
2. Open a saved post or page with an explicit HTML anchor on a heading. In the block editor settings, open the post or page tab and expand Heading anchor check.
3. Change the anchor in the draft and choose Compare heading targets before saving. Restore the original anchor and compare again to check the result.

== Frequently Asked Questions ==

= Where does the comparison run? =

The plugin compares the saved and edited post bodies in the block editor in your browser. It sends neither version to an external service. After another edit, run the comparison again.

= Will this find the pages that link to a heading? =

It checks whether a saved heading target still exists. It does not crawl incoming links or create redirects. If the old target still exists on a different block, check where the link lands before publishing.

= What if there are no saved heading IDs to compare? =

The check needs explicit, nonempty HTML IDs on headings in the saved post body. A heading without an HTML anchor is not a target in this comparison. The message that there are no explicit heading IDs is not a check of every link on the page. If saved or edited source is unavailable, the panel reports that no comparison was made.

= Does a zero-missing result prove that every link goes to the right place? =

No. If a saved heading used delivery, both an element with id="delivery" and an HTML anchor with name="delivery" can be destinations. When two different elements match, the panel warns about the duplicate even if no target is missing. Keep delivery on the intended heading and remove or rename the other target. Select Compare heading targets again before saving.

The warning covers only targets belonging to saved headings. A single matching target on the wrong block can still pass, so check where the link lands.

= How do I fix a missing target and a duplicate in the same draft? =

Suppose the saved headings used delivery and returns. In your draft, you renamed delivery to shipping, and both the Returns heading and a paragraph now use returns. The missing target is #delivery. Restore delivery on the intended heading. The duplicate target is #returns. Keep returns on the Returns heading and remove or rename the paragraph's anchor. Select Compare heading targets again before saving. With both repairs in place, expect zero missing targets and no duplicate warning.

= Why did my previous result disappear? =

The panel hides a previous result when the saved post or edited content changes and asks you to compare again. It does not block saving or repair anchors automatically. Compare before updating the post: once saved, that version becomes the new baseline, not a history of earlier anchors.

== Changelog ==

= 0.2.1 =
* Clarify which saved target is missing and which has multiple matches when both issues appear in one comparison.

= 0.2.0 =
* Warn when a saved heading anchor matches multiple elements in the edited post or page.

= 0.1.0 =
* Compare saved heading targets with an edited post or page and list the missing targets before saving.
