How To Automatically Add Custom Fields On Post Publish In WordPress

If you have a created a function or a modification in your theme which requires you to manually add a default custom field whenever you publish a new post, then you’re doing it wrong. Why do it manually when we can automatically add custom fields on posts when they get publish first? It can also helps if you’re creating a site for client.

Just drop the following code into your current theme’s functions.php file:

Just field-name and custom value with your Custom Field Name, and the Value. You can use also this trick will custom post types.