I got some plugins that auto-generates custom fields. Does anyone know how to automatically remove empty custom fields from post when I press “publish”?
A check I can put in my functions.php that does a check and removes the custom field if there is no value?
Here is the solution:
wp_insert_post_data is a hook that happens before a database write in the admin panel. You can probably use that to call a function that checks for data, then strips out any empty custom field entries.
Or, you could use the_content hooks on the front end to strip out empty custom fields before they get displayed to the user.
Or, if you have control of the theme files, you can just test for data in your custom fields before displaying them.