Digital Sovereignty for everyone

Developer reference

What is changed

On a single post, page or custom post type, the main post’s content is parsed with PHP’s DOMDocument and every p, h1, h2, h3 and h4 element without an id gets id="lh_element_id-{tag}{post ID}-{n}", where n counts from 0 for each tag. Every one of those elements gets the class lh-paragraph-id. Nothing is done where the DOM extension is not available.

When content is changed

A the_content filter at priority 10 is added on template_redirect for singular, non-feed requests. It acts once per request, only on the queried post’s content, and only when that content is rendered for the page body: after wp_body_open in classic and PHP templates, or while a block template renders its markup (after template_include, before wp_head). Content run for the page head, such as excerpts built for meta tags, and content of other posts shown on the page are left alone.

Filters

  • lh_paragraph_ids_return_elegible_tags: the tag names that get ids (default p, h1 to h4). Adding a tag numbers it from 0 without changing the ids of the others.
  • lh_paragraph_ids_link_enabled: return true to add the ¶ paragraph links (default false).
  • lh_paragraph_ids_init_plugin: return false to switch the plugin off in code without deactivating it.

Script

The paragraph link script (handle lh_paragraph_ids-script, deferred, in the footer) is enqueued only when links are enabled and the content has paragraphs. It appends <span> <a class="lh-paragraph-id-anchor" href="#{id}">¶</a></span> to every p.lh-paragraph-id with an id. The link title (“Link to this paragraph”) is translatable.

If you like this plugin please consider making a donation to further development

Install LHero.org

lhero.org

Open it straight from your home screen, full screen and quicker to load.

  1. Tap the Share button . If you cannot see it, tap ••• first.
  2. Scroll down and tap Add to Home Screen.
  3. Tap Add.
  1. Tap the browser menu â‹®.
  2. Tap Install app or Add to Home screen.
  1. In the menu bar, choose File, then Add to Dock.

Use your browser's menu to install this site or add it to your home screen.