llms.txt in WordPress
Add an llms.txt file to your WordPress site in minutes. Three methods, pick the one that matches your hosting setup.
Last updated:
Three methods compared
WordPress does not have a built-in way to serve arbitrary files at the domain root. Here are three approaches, ordered from simplest to most powerful:
- Method 1, FTP upload: Upload
llms.txtdirectly to the server root via FTP/SFTP. No code required. Best for shared hosting and static content that rarely changes. - Method 2, functions.php rewrite: Register a custom WordPress rewrite rule that
serves a dynamically generated
llms.txt. Best if you want the file to update automatically when you publish new pages. - Method 3, .htaccess redirect: Redirect
/llms.txtto a static file or another URL using Apache\'s.htaccess. A useful fallback when you cannot upload directly to the root.
Method 1: FTP file upload
This is the simplest and most reliable method. WordPress is installed at the root of your domain (or a subdirectory), and anything you place in that folder is served by the web server directly, without going through WordPress at all.
- Write your
llms.txtfile. Use the generator to create the file, or write it by hand following the how-to guide. Save it locally asllms.txt. - Connect via FTP/SFTP. Use FileZilla, Cyberduck, or your hosting control panel\'s file manager. Connect to your server.
- Navigate to the WordPress root. This is the folder that contains
wp-config.php,wp-content/, andindex.php. - Upload
llms.txtto that folder. - Verify: Visit
https://yourdomain.com/llms.txtin a browser. You should see plain text.
Method 2: Dynamic file via functions.php
If you want llms.txt to be generated dynamically from your WordPress content, for example,
listing your most recent posts or key pages automatically, you can hook into WordPress\'s rewrite
system.
Add the following to your theme\'s functions.php or a site-specific plugin:
/**
* Serve a dynamic /llms.txt via WordPress rewrite.
*/
add_action( 'init', function() {
add_rewrite_rule( 'llms\.txt$', 'index.php?llms_txt=1', 'top' );
} );
add_filter( 'query_vars', function( $vars ) {
$vars[] = 'llms_txt';
return $vars;
} );
add_action( 'template_redirect', function() {
if ( ! get_query_var( 'llms_txt' ) ) {
return;
}
$site_name = get_bloginfo( 'name' );
$site_url = home_url();
$desc = get_bloginfo( 'description' );
// Build a curated list, customize as needed
$pages = [
[ 'title' => 'Home', 'url' => home_url( '/' ), 'desc' => 'Site entry point.' ],
[ 'title' => 'Blog', 'url' => home_url( '/blog/' ), 'desc' => 'Latest articles.' ],
[ 'title' => 'About', 'url' => home_url( '/about/' ), 'desc' => 'About this site.' ],
[ 'title' => 'Contact', 'url' => home_url( '/contact/' ), 'desc' => 'Contact form.' ],
];
$lines = [];
$lines[] = "# ${site_name}";
$lines[] = '';
$lines[] = "> ${$desc}";
$lines[] = '';
$lines[] = '## Core pages';
$lines[] = '';
foreach ( $pages as $page ) {
$lines[] = "- [${$page['title']}](${$page['url']}): ${$page['desc']}";
}
$lines[] = '';
header( 'Content-Type: text/plain; charset=utf-8' );
echo implode( "\n", $lines );
exit;
} );
After adding this code, go to Settings → Permalinks in the WordPress admin and click
Save Changes to flush the rewrite rules. Then visit
/llms.txt to confirm it works.
.htaccess redirect
If you cannot upload a file to the root directly, but you can edit .htaccess, you
can redirect /llms.txt to any other URL (including an uploaded file elsewhere on your
server, or an external URL).
Add the following to your .htaccess file, before the WordPress rewrite
block:
# llms.txt redirect, place BEFORE the WordPress block
RewriteEngine On
RewriteRule ^llms\.txt$ /wp-content/uploads/llms.txt [L,R=301]
This redirects https://yourdomain.com/llms.txt to a file you\'ve uploaded via the WordPress
Media Library (or manually placed in wp-content/uploads/). Note that redirecting
with a 301 means the actual file URL will be visible to users and bots, that is fine for most
use cases.
If you want to serve the file without a redirect (at the canonical /llms.txt URL), Method
1 (FTP) or Method 2 (rewrite rule) is preferable.
Verifying the setup
Regardless of which method you use, verify the result:
-
Visit
https://yourdomain.com/llms.txt, you should see plain text with no HTML wrapper. -
Run:
curl -I https://yourdomain.com/llms.txtand check for200 OKandContent-Type: text/plain. - Paste the URL into the llmtxt.info validator to confirm spec compliance.
-
Confirm
llms.txtis not accidentally blocked in yourrobots.txt.
Continue reading
- How to create llms.txt, general guide with format reference.
- Generator, fill a form and download your file.
- Best practices, what to include for maximum usefulness.
- llms.txt and SEO, what it does and does not do for rankings.