Txt files keeps content from fields that no longer exist

As a site is being developed and content added, I often find fields are no longer needed or are renamed for different content. The old content from fields no longer existing still exists in the pages .txt files. Maybe this is over-the-top and unnecessary, but I find this messy and often go through the .txt files removing old unused content.

Is there a way to tell Kirby not to keep content from fields that no longer exist? Or an easy way to remove this content, rather than manually going through each .txt file?

The Kirby CLI has a clean:content command for this

kirby clean:content

Is it possible to do without using Kirby command line? That looks well beyond my capabilities.

You can also check out @texnixe cookbook article on how to create a custom script for it Content clean-up | Kirby CMS

Okay… where or what do I do with the code?

It’s all explained in the article.

So I create a file called cleanup.php add the code to the file and then add the file to my server. Then I visit the page http://yourdomain.com/cleanup.php. And this runs the script? I don’t know how to run a script?

I would recommend to do this in your local environment and not on the server. This way, you can test the script first and see if the results are ok for you.

Visiting the URL should normally be all it needs to run the script. You need to use your own local domain instead of yourdomain.com of course :slight_smile:

Great, thanks for clearing that up. I spent a few hours manually clearing up the txt files, so I’ll now have to create a dummy field and check it out.

Works brilliantly, thanks

1 Like