Custom Fields store meta-data within a post that allows you to store extra information. Custom fields are a very handy feature and are very easy to add. But if you are adding lots of posts that all require the same custom field, it can become a bit repetitive having to add the same custom field over and over again. Simply paste the below code into your functions.php file and each new post will have your desired custom field by default.
add_action('wp_insert_post', 'set_default_custom_fields');
function set_default_custom_fields($post_id){
if ( $_GET['post_type'] == 'post' ) {
add_post_meta($post_id, 'Field Name', '', true);
add_post_meta($post_id, 'Another Field Name', '', true);
}
return true;
}
By default this will add an empty custom field to your post. If you want to enter a value by default too, use the code below.
add_action('wp_insert_post', 'set_default_custom_fields');
function set_default_custom_fields($post_id){
if ( $_GET['post_type'] == 'post' ) {
add_post_meta($post_id, 'Field Name', 'Field Value', true);
}
return true;
}