drupal 8 how to set metadata field
Working in Drupal 8 and need to set a metadata field value programmatically? Navigating just what array to pass and all that sort of stuff is a headache, but I've got your back!
$meta_data = []
$meta_data['canonical_url'] = 'http://www.woohoo.com';
$entity->set('field_name_metatags', serialize($meta_data));
Please note that you can also load the previous value for your meta tags field, unserialize that value, then make your changes, and save it again serialized!