Title: BUG Skip headings function
Last modified: April 14, 2026

---

# BUG Skip headings function

 *  [zielniok](https://wordpress.org/support/users/zielniok/)
 * (@zielniok)
 * [1 month, 1 week ago](https://wordpress.org/support/topic/bug-skip-headings-function/)
 * I’d like to report a bug in the “Skip headings” feature (Misc settings).
 * The skip logic in `plugin/contentHandling/ContentHandling.php` runs after the
   heading has already been added to `$result->headings[]`. This means the heading
   still appears in the table of contents — only the anchor span in the content 
   is skipped.
 * Relevant code (around line 56–66):
 *     ```wp-block-code
       $result->headings[] = [
           'id' => $id,
           'index' => $index,
           'label' => $label,
       ];
   
       if (!$dto->modify ||
           in_array('h' . $index, $dto->skipLevels) ||
           ($skipRegex && preg_match($skipRegex, $label))
       ) {
           continue;
       }
       ```
   
 * The `continue` skips inserting the anchor `<span>` into the content, but the 
   heading has already been pushed to the result array. So the TOC entry is still
   rendered, but without a working anchor link — which is worse than not skipping
   at all.
 * Expected behavior: A heading matched by the skip pattern should be excluded from
   the TOC, but its anchor ID should still be inserted into the content (for external
   links pointing to that heading).
 * The fix would be to separate the two concerns:
    1. Always insert the anchor span (or at least when `$dto->modify` is true)
    2. Only add the heading to `$result->headings[]` if it does not match the skip 
       pattern
 * Thank you for looking into this!

You must be [logged in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fbug-skip-headings-function%2F%3Foutput_format%3Dmd&locale=en_US)
to reply to this topic.

 * ![](https://ps.w.org/luckywp-table-of-contents/assets/icon-256x256.png?rev=2100677)
 * [LuckyWP Table of Contents](https://wordpress.org/plugins/luckywp-table-of-contents/)
 * [Support Threads](https://wordpress.org/support/plugin/luckywp-table-of-contents/)
 * [Active Topics](https://wordpress.org/support/plugin/luckywp-table-of-contents/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/luckywp-table-of-contents/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/luckywp-table-of-contents/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [zielniok](https://wordpress.org/support/users/zielniok/)
 * Last activity: [1 month, 1 week ago](https://wordpress.org/support/topic/bug-skip-headings-function/)
 * Status: not resolved