Kirby Robots Writer - Version 0.2 released

There are already four other robots plugins:

…so why make another one?

I really wanted to open up the possibilities to add robots.txt content anywhere you want, in a snippet, in a site field or in a page field.

Plenty of options, in this tiny plugin:

Robots by snippet

In config.php, add something like this:

c::set('plugin.robots.writer.type', 'snippet');
c::set('plugin.robots.writer.snippet.name', 'robots');

Add a snippet in the snippet folder or register one in a plugin like this:

$kirby->set('snippet', 'robots', __DIR__ . '/snippets/robots.php');

https://getkirby.com/docs/developer-guide/plugins/registry

Robots by site

In config.php, add something like this:

c::set('plugin.robots.writer.type', 'site');
c::set('plugin.robots.writer.field.name', 'robots');

In site.txt add something like this:

fields:
  robots:
    title: Robots
    type: textarea

Robots by page

In config.php, add something like this:

c::set('plugin.robots.writer.type', 'page');
c::set('plugin.robots.writer.field.name', 'robots');
c::set('plugin.robots.writer.page.uri', 'my/custom/page');

In my_template.txt add something like this:

fields:
  robots:
    title: Robots
    type: textarea

Enjoy! :slight_smile:

1 Like

Thanks for that plugin!.
but what are robots ?

“robots” in the context of this plugin refers to “robots.txt”, the file that tells search engines (and other bots) which files they may access. If you google “robots.txt”, you should find a lot of information on the topic.

2 Likes

I really like moz.com and they have a nice article about robots.txt:

1 Like

Version 0.2 is released and completely rewritten. Sounds like alot of work, but it’s just 12 lines of code.

Into your config.php:

c::set('robots.txt', '
User-agent: *
Disallow: /
Sitemap: https://example.com/sitemap.xml
');

robots.txt output:

User-agent: *
Disallow: /
Sitemap: https://example.com/sitemap.xml

Alternative solution - Snippet

Make sure your snippet exists and is registered:

c::set('robots.txt', snippet('robots.txt', [], true));

Alternative solution - Site

Make sure you have a field called robots in site.

c::set('robots.txt', site()->robots());
1 Like