This part is not required
It is there as a helper function if you need to clean up the metas before adding them as tags.
// See also https://gist.github.com/kricore/2c9a5434748c5f5f6cf9
// Cleanup the extrafields content so you can use them as metatags
$safe = array("", "");
$nonsafe = array("'", "\"");
$custometa = $this->item->extraFields->newtitle->value;
$safemeta = str_replace( $nonsafe, $safe, $custometa);
echo $safemeta;
In my last post, I mentioned two methods from Joomla!'s API instead of addCustomTag (check the links).
Can you try these methods instead?