Simply add the code bellow in your functions.php file inside your theme’s folder. And don’t forget to change the custom field name.

add_action('publish_page', 'add_custom_field_automatically');
add_action('publish_post', 'add_custom_field_automatically');
function add_custom_field_automatically($post_ID) {
	global $wpdb;
	if(!wp_is_post_revision($post_ID)) {
		add_post_meta($post_ID, 'field-name', 'custom value', true);
	}
}

That’s it. Hope this helps.

Visit the best themes marketplace with over 600 premium wordpress themes.