{$description}\n\n"; } $out .= "An LLM-readable index of {$name}. Follow the links for the full content.\n\n"; // Discovery endpoints — only list features that are currently enabled. $discovery = array(); if ( is_feature_enabled( 'api_catalog' ) ) { $discovery[] = '[API Catalog](' . esc_url( home_url( '/.well-known/api-catalog' ) ) . '): RFC 9727 link set advertising REST endpoints, documentation, and health.'; } if ( is_feature_enabled( 'openapi' ) ) { $discovery[] = '[OpenAPI Spec](' . esc_url( home_url( '/?format=openapi' ) ) . '): OpenAPI 3.0.3 specification of every REST route on this site.'; } if ( is_feature_enabled( 'agent_skills_index' ) ) { $discovery[] = '[Agent Skills Index](' . esc_url( home_url( '/.well-known/agent-skills/index.json' ) ) . '): skills agents can use, each with a verifiable SKILL.md artifact.'; } if ( is_feature_enabled( 'mcp_server_card' ) ) { $discovery[] = '[MCP Server Card](' . esc_url( home_url( '/.well-known/mcp/server-card.json' ) ) . '): SEP-1649 server descriptor.'; } if ( ! empty( $discovery ) ) { $out .= "## Discovery\n\n"; foreach ( $discovery as $line ) { $out .= "- {$line}\n"; } $out .= "\n"; } // Top-level pages. $pages = get_posts( array( 'post_type' => 'page', 'post_status' => 'publish', 'numberposts' => 20, 'post_parent' => 0, 'orderby' => 'menu_order title', 'order' => 'ASC', 'suppress_filters' => false, ) ); if ( ! empty( $pages ) ) { $out .= "## Pages\n\n"; foreach ( $pages as $page ) { $out .= '- ' . format_llms_txt_entry( $page ) . "\n"; } $out .= "\n"; } // Recent posts. $posts = get_posts( array( 'post_type' => 'post', 'post_status' => 'publish', 'numberposts' => 10, 'orderby' => 'date', 'order' => 'DESC', 'suppress_filters' => false, ) ); if ( ! empty( $posts ) ) { $out .= "## Recent Posts\n\n"; foreach ( $posts as $post ) { $out .= '- ' . format_llms_txt_entry( $post, true ) . "\n"; } $out .= "\n"; } /** * Filter the final llms.txt body. * * Themes and plugins can append their own sections (e.g. featured products, * upcoming events, custom-post-type listings) or replace the body wholesale. * Return value is served verbatim with `Content-Type: text/markdown`. * * @param string $out The Markdown body about to be served. */ return (string) apply_filters( 'ajaco_llms_txt_content', $out ); } /** * Format a single post/page entry for llms.txt. * * @param \WP_Post $p * @param bool $with_date Append the publish date in parentheses. * @return string */ function format_llms_txt_entry( \WP_Post $p, bool $with_date = false ): string { $title = esc_html( get_the_title( $p ) ); $url = esc_url( get_permalink( $p ) ); $excerpt = trim( wp_strip_all_tags( get_the_excerpt( $p ) ) ); $excerpt = preg_replace( '/\s*\[(\.\.\.|…)\]\s*$/u', '', $excerpt ); $excerpt = esc_html( $excerpt ); $line = "[{$title}]({$url})"; if ( $with_date ) { $line .= ' (' . esc_html( get_the_date( 'Y-m-d', $p ) ) . ')'; } if ( $excerpt !== '' ) { $line .= ': ' . $excerpt; } return $line; }