Docs & Support

Learn about all Business Directory’s features and get support from our amazing customer success team.

CustomizationsHooks – For Developers
Add field to listing contact form

Add field to listing contact form

This article provides instructions for how to add a phone number to the Listing Contact form. The code could be different for what you might want to do.

To accomplish this with Business Directory Plugin, you will follow the instructions at the top of the developer hooks page.

/* Puts the field on the contact form at the bottom */
function example_add_custom_contact_field() {
  echo '<p>Phone Number: <input type="text" name="phone-number" /></p>';
}
add_action( 'wpbdp_contact_form_extra_fields', 'example_add_custom_contact_field' );

/* Validates the field if necessary */
function example_validate_custom_contact_field( $errors ) {
  if ( empty( $_POST['phone-number'] ) ) {
    $errors['phone-number'] = 'Phone number is required!';
  }
  return $errors;
}
add_filter( 'wpbdp_contact_form_validation_errors', 'example_validate_custom_contact_field' );

/* Adds the field to the body of the contact email sent to the listing owner */
function example_add_custom_contact_field_to_email( $body ) {
  if ( isset( $_POST['phone-number'] ) ) {
    $body .= "\n\n";
    $body .= 'Phone Number: ';
    $body .= sanitize_text_field( $_POST['phone-number'] );
  }
  return $body;
}
add_filter( 'wpbdp_contact_form_email_body', 'example_add_custom_contact_field_to_email' );
Was this article helpful? *

This article may contain affiliate links. Once in a while, we earn commissions from those links. But we only recommend products we like, with or without commissions.

In this article

    We have a small, but amazing team of dedicated people who are committed to helping you achieve your goals and project requirements.


    Copyright © 2010-2025 S11 Directories, LLC.

    Join 20,000+ using Business Directory Plugin to build website directories fast. Get Started