Try renaming /site/plugins/structure.php
to /site/plugins/structure/index.php
and put this inside:
<?php
use Kirby\Cms\Structure;
function createNewStructure($pages, $field)
{
// instantiate a new structure object
$structure = new Structure();
// loop through the pages collection
foreach ($pages as $p) {
$structure->add($p->$field()->toStructure());
}
return $structure;
}