I have created my own custom field type to generate the ‘duration’ property of the VideoObject schema by following the instructions on this page: https://rich-snippets.io/how-to-add-your-own-field-type/
My custom function essentially takes the unformatted duration from a custom field and converts it to ISO 8601 format. However, when the custom field is blank, the function returns no value (as expected). So the schema ends up displaying “duration”:null. Is there a way I can prevent the duration property from being generated when the custom function returns no value?
2 thoughts on “Custom Field Type – How to not display a property when its value is NULL”
and thanks for your question. Did you try to return an empty string if the value is NULL? SNIP normally removes properties when their values are empty.
I’ve updated the code to return an empty string and that worked! Thank you