custom field value is blank or empty
You need to pass the $post_id into the get_the_content() : function add_custom_fields($post_id) { global $post; $metadescription = wp_trim_words( get_the_content($post_id), 55 ); add_post_meta($post_id, ‘meta_description’, ” . $metadescription . ”, true); } add_action(‘wp_insert_post’, ‘add_custom_fields’);