Helping Organisations get organised!

Developer reference

Filters

Filter Arguments Use
lh_ai_legibility_init_plugin bool $init Return false to switch the plugin off without deactivating it.
lh_ai_legibility_markdown_enabled bool $enabled, WP_Post $post Return false to stop serving Markdown for a post, or for a whole post type. Also keeps the post out of llms-full.txt and out of archive pages served as Markdown.
lh_ai_legibility_markdown_output string $markdown, WP_Post $post Change a post’s Markdown, without its front matter, both in a response to an Accept: text/markdown request and where the post appears in llms-full.txt.
lh_ai_legibility_archive_markdown_enabled bool $enabled, WP_Query $query Return false to stop serving an archive page, or all of them, as Markdown.
lh_ai_legibility_archive_item_summary string $summary, WP_Post $post The one-line summary after a post’s link on an archive page served as Markdown. By default its excerpt, only when one was written; empty for none.
lh_ai_legibility_llms_txt_output string $output Change the final /llms.txt output.
lh_ai_legibility_llms_full_output string $output Change the final /llms-full.txt output.
lh_ai_legibility_return_max_http_checks int $max Most links the llms.txt abilities request over HTTP in one call, when asked to check every link. Default 25.

Identifiers

Each identifier is returned by a static method on LH_AI_Legibility_Llms_Txt and can be changed with the filter of the same name. Change them only before any llms.txt document exists, since existing documents and the stored option use the old values.

Filter Default What it names
lh_ai_legibility_return_post_type llms_txt_document The llms.txt document post type
lh_ai_legibility_return_index_query_var lh_llms_txt The query variable behind /llms.txt
lh_ai_legibility_return_full_query_var lh_llms_full_txt The query variable behind /llms-full.txt
lh_ai_legibility_return_document_option_name lh_ai_legibility_document_id The option holding the site’s document ID

The section block is lh-ai-legibility/section (named llms-txt/section before 0.5.1). Its name is fixed in block.json and the editor script, so it is not filterable.

What is served as Markdown

  • Any single post, page or other singular post type, when the request’s Accept header lists text/markdown and prefers it to text/html.
  • Never a private post, and never a post with a password, even to a visitor who has entered it, since a Markdown response can be cached.
  • The front matter gives title, URL, dates, post type, the excerpt only when one has been written, and the first category if there is one.
  • Archive pages (the posts page, and post type, taxonomy, date and author archives) as a list of links to the same posts, in the same order and with the same paging as the HTML page, each with its summary. The front matter gives the page number and total pages, and the list ends with links to the previous and next pages. Search results and feeds are not served as Markdown.

Headers and caching

  • HTML responses carry Vary: Accept, so a CDN or proxy cache that honours it keeps the HTML and Markdown versions of a page apart.
  • HTML responses for posts and archive pages that can be served as Markdown also carry a Link header with rel="alternate"; type="text/markdown", so an agent that reads response headers can discover the Markdown version without knowing to ask for it.
  • Markdown responses, /llms.txt and /llms-full.txt send Cache-Control: public, max-age=3600.
  • Rewrite rules for /llms.txt and /llms-full.txt are flushed whenever the llms.txt document is saved, including when its draft is first created.

LiteSpeed

LiteSpeed’s page cache ignores Vary: Accept, so without help it would serve a cached Markdown version of a page to browsers, or a cached HTML page to Markdown requests. On a LiteSpeed server the plugin therefore adds this block to the top of the root .htaccess, which gives Markdown requests a cache of their own:

# BEGIN LH AI Legibility LiteSpeed Cache
<IfModule LiteSpeed>
RewriteEngine On
RewriteCond %{HTTP:Accept} text/markdown [NC]
RewriteRule ^ - [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+ismarkdown]
</IfModule>
# END LH AI Legibility LiteSpeed Cache
  • It is added on activation, and checked at most once a day when someone who can install plugins opens wp-admin on the main site.
  • It is only added if it is not already there, found by its marker or by +ismarkdown, so a block added by hand is left alone. It is never added if the file cannot be read or written directly.
  • It goes at the top because a rule after WordPress’s own rewrite never runs.
  • It is not removed on deactivation. Left in place it only splits the cache, so remove it by hand if you no longer want it.

If the site uses any other full-page cache, check that it varies on Accept. Either exclude /llms.txt and /llms-full.txt from it or make sure it clears when the llms.txt document is saved, otherwise edits will not show until the cached copy expires.

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