How to index and prevent indexing of categories that I have in the same Collection

Hello everyone. I have a collection with some categories. What I wanna do is that some of those categories get properly indexed, and this part if fine. But some other categories I want that they dont get indexed.

What I tried to do was create a field for all categories called “Meta No Index” and in there I put the code “”. And in the SEO settings of this collection page I linked this field in custom code of the “HEAD”.

So in theory the categories that I dont want to be indexed this code would appear in the HEAD. But as I checked in the live website, this custom code is actually showing inside the BODY tag, not in the HEAD. Therefore the browser is not reading as a proper META tag.

Am I doing something wrong? Or maybe is there an easy way to achive the same thing?