PHP code example of roots / acorn-llms-txt
1. Go to this page and download the library: Download roots/acorn-llms-txt library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
roots / acorn-llms-txt example snippets
'post_types' => ['post', 'page'],
'content' => [
'process_shortcodes' => true, // Process WordPress shortcodes
' true,
'excerpt_length' => 20,
'date_format' => 'Y-m-d',
],
'limits' => [
'max_posts' => 1000,
'max_content_length' => 50000,
'posts_per_section' => 50,
],
'exclude' => [
'post_ids' => [123, 456], // Specific posts to exclude
'password_protected' => true,
'sticky_posts' => false,
],
'individual_posts' => [
'enabled' => false, // Enable /post-slug.txt endpoints
'post_types' => ['post', 'page'],
'cache_ttl' => 3600,
],
'cache_ttl' => 3600, // 1 hour in seconds
'woocommerce' => [
'enabled' => true, // Enable WooCommerce integration
't_type' => false, // Include product type
],
add_filter('acorn/llms_txt/post_types', function ($postTypes) {
return array_merge($postTypes, ['custom_post_type']);
});
add_filter('acorn/llms_txt/exclude_post', function ($exclude, $post) {
return $post->post_title === 'Secret Post';
}, 10, 2);
add_filter('acorn/llms_txt/post_data', function ($data, $post) {
$data['custom_field'] = get_post_meta($post->ID, 'custom_field', true);
return $data;
}, 10, 2);
add_filter('acorn/llms_txt/posts', function ($posts) {
return $posts->sortBy('title');
});
add_filter('acorn/llms_txt/document', function ($document) {
// Modify the LlmsTxtDocument object
return $document;
});
add_filter('acorn/llms_txt/content', function ($content) {
return $content . "\n\n<!-- Generated at " . date('Y-m-d H:i:s') . " -->";
});
add_filter('acorn/llms_txt/sitemap', function ($sitemap) {
// Modify the XML sitemap content
return $sitemap;
});
add_filter('acorn/llms_txt/egration conditionally
return false;
});
add_action('acorn/llms_txt/before_sections', function ($document) {
$section = (new \Roots\AcornLlmsTxt\Data\Section)
->name('Custom Section')
->addLink(
(new \Roots\AcornLlmsTxt\Data\Link)
->title('Custom Link')
->url('https://example.com')
->details('Custom description')
);
$document->addSection($section);
});
add_action('acorn/llms_txt/after_sections', function ($document) {
// Add sections after default content
});
add_action('acorn/llms_txt/custom_sections', function ($document) {
// Add your own sections
});
'limits' => [
'max_posts' => 500,
'max_content_length' => 25000,
],