template-contact.php

I’ll build this as a real advanced WordPress page template, not only HTML: secure form handling, nonce, honeypot, rate-limit, sanitization, contact sections, schema, accessibility, and theme-friendly hooks/classes.

Absolutely friend. Create or replace this file:

rx-theme/templates/template-contact.php

This is an advanced Contact Page Template for RX Theme with secure contact form, nonce, honeypot, simple rate limit, validation, success/error messages, contact cards, opening hours, map section, FAQ section, JSON-LD schema, accessibility, and many RX Theme hooks.

<?php
/**
 * Template Name: RX Contact Page
 * Template Post Type: page
 *
 * Advanced Contact Page Template for RX Theme.
 *
 * Features:
 * - Secure contact form
 * - WordPress nonce verification
 * - Honeypot spam protection
 * - Simple transient-based rate limiting
 * - Sanitization and validation
 * - Email delivery using wp_mail()
 * - Success and error notice system
 * - Contact information cards
 * - Clinic / hospital hours section
 * - Emergency notice section
 * - Google Map / iframe-safe area
 * - FAQ section
 * - JSON-LD schema for medical/organization contact page
 * - Accessibility-friendly markup
 * - Developer hooks and filters
 *
 * @package RX_Theme
 */

defined( 'ABSPATH' ) || exit;

get_header();

/**
 * ------------------------------------------------------------
 * RX CONTACT TEMPLATE HELPERS
 * ------------------------------------------------------------
 */

if ( ! function_exists( 'rx_contact_get_option' ) ) {
	/**
	 * Get theme mod with fallback.
	 *
	 * @param string $key     Theme mod key.
	 * @param mixed  $default Default value.
	 * @return mixed
	 */
	function rx_contact_get_option( $key, $default = '' ) {
		return get_theme_mod( $key, $default );
	}
}

if ( ! function_exists( 'rx_contact_clean_phone' ) ) {
	/**
	 * Clean phone number for tel link.
	 *
	 * @param string $phone Phone number.
	 * @return string
	 */
	function rx_contact_clean_phone( $phone ) {
		return preg_replace( '/[^0-9+]/', '', (string) $phone );
	}
}

if ( ! function_exists( 'rx_contact_allowed_html' ) ) {
	/**
	 * Allowed HTML for contact template content.
	 *
	 * @return array
	 */
	function rx_contact_allowed_html() {
		return array(
			'a'      => array(
				'href'   => array(),
				'title'  => array(),
				'target' => array(),
				'rel'    => array(),
				'class'  => array(),
			),
			'br'     => array(),
			'strong' => array(),
			'em'     => array(),
			'span'   => array(
				'class' => array(),
			),
			'p'      => array(
				'class' => array(),
			),
		);
	}
}

if ( ! function_exists( 'rx_contact_get_client_ip' ) ) {
	/**
	 * Get client IP safely.
	 *
	 * This is not perfect because proxies/CDNs may hide IP,
	 * but it is enough for simple form rate limiting.
	 *
	 * @return string
	 */
	function rx_contact_get_client_ip() {
		$ip_keys = array(
			'HTTP_CF_CONNECTING_IP',
			'HTTP_X_FORWARDED_FOR',
			'HTTP_CLIENT_IP',
			'REMOTE_ADDR',
		);

		foreach ( $ip_keys as $key ) {
			if ( ! empty( $_SERVER[ $key ] ) ) {
				$ip_list = explode( ',', sanitize_text_field( wp_unslash( $_SERVER[ $key ] ) ) );
				$ip      = trim( $ip_list[0] );

				if ( filter_var( $ip, FILTER_VALIDATE_IP ) ) {
					return $ip;
				}
			}
		}

		return '0.0.0.0';
	}
}

if ( ! function_exists( 'rx_contact_get_current_url' ) ) {
	/**
	 * Get current page URL.
	 *
	 * @return string
	 */
	function rx_contact_get_current_url() {
		global $wp;

		if ( isset( $wp->request ) ) {
			return home_url( add_query_arg( array(), $wp->request ) );
		}

		return get_permalink();
	}
}

/**
 * ------------------------------------------------------------
 * DEFAULT CONTACT DATA
 * ------------------------------------------------------------
 */

$rx_contact_defaults = array(
	'hero_kicker'       => rx_contact_get_option( 'rx_contact_hero_kicker', __( 'Contact RX Health Team', 'rx-theme' ) ),
	'hero_title'        => rx_contact_get_option( 'rx_contact_hero_title', get_the_title() ),
	'hero_description'  => rx_contact_get_option(
		'rx_contact_hero_description',
		__( 'Have a question, appointment request, medical content inquiry, or website support message? Send us a message and our team will respond as soon as possible.', 'rx-theme' )
	),

	'office_name'       => rx_contact_get_option( 'rx_contact_office_name', get_bloginfo( 'name' ) ),
	'doctor_name'       => rx_contact_get_option( 'rx_contact_doctor_name', __( 'RX Health Team', 'rx-theme' ) ),
	'phone'             => rx_contact_get_option( 'rx_contact_phone', '+880 0000 000000' ),
	'emergency_phone'   => rx_contact_get_option( 'rx_contact_emergency_phone', '+880 0000 000000' ),
	'email'             => rx_contact_get_option( 'rx_contact_email', get_option( 'admin_email' ) ),
	'address'           => rx_contact_get_option( 'rx_contact_address', __( 'Your hospital / chamber address here', 'rx-theme' ) ),
	'city'              => rx_contact_get_option( 'rx_contact_city', 'Khalisha' ),
	'country'           => rx_contact_get_option( 'rx_contact_country', 'Bangladesh' ),

	'hospital_hours'    => rx_contact_get_option( 'rx_contact_hospital_hours', __( 'Hospital: 9:00 AM – 4:00 PM', 'rx-theme' ) ),
	'chamber_hours'     => rx_contact_get_option( 'rx_contact_chamber_hours', __( 'Chamber: Around 9:00 PM', 'rx-theme' ) ),
	'weekly_off'        => rx_contact_get_option( 'rx_contact_weekly_off', __( 'Weekly schedule may change. Please call before visiting.', 'rx-theme' ) ),

	'map_embed'         => rx_contact_get_option( 'rx_contact_map_embed', '' ),
	'map_link'          => rx_contact_get_option( 'rx_contact_map_link', '#' ),

	'facebook'          => rx_contact_get_option( 'rx_contact_facebook', '' ),
	'youtube'           => rx_contact_get_option( 'rx_contact_youtube', '' ),
	'linkedin'          => rx_contact_get_option( 'rx_contact_linkedin', '' ),
	'x_twitter'         => rx_contact_get_option( 'rx_contact_x_twitter', '' ),

	'enable_form'       => (bool) rx_contact_get_option( 'rx_contact_enable_form', true ),
	'enable_map'        => (bool) rx_contact_get_option( 'rx_contact_enable_map', true ),
	'enable_faq'        => (bool) rx_contact_get_option( 'rx_contact_enable_faq', true ),
	'enable_schema'     => (bool) rx_contact_get_option( 'rx_contact_enable_schema', true ),
	'enable_emergency'  => (bool) rx_contact_get_option( 'rx_contact_enable_emergency', true ),
);

$rx_contact_data = apply_filters( 'rx_theme_contact_template_data', $rx_contact_defaults );

/**
 * ------------------------------------------------------------
 * FORM PROCESSING
 * ------------------------------------------------------------
 */

$rx_contact_errors  = array();
$rx_contact_success = false;
$rx_contact_values  = array(
	'name'    => '',
	'email'   => '',
	'phone'   => '',
	'subject' => '',
	'type'    => '',
	'message' => '',
	'privacy' => '',
);

if (
	isset( $_SERVER['REQUEST_METHOD'] )
	&& 'POST' === strtoupper( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_METHOD'] ) ) )
	&& isset( $_POST['rx_contact_form_submitted'] )
) {
	/**
	 * Nonce verification.
	 */
	if (
		! isset( $_POST['rx_contact_nonce'] )
		|| ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['rx_contact_nonce'] ) ), 'rx_contact_form_action' )
	) {
		$rx_contact_errors[] = __( 'Security check failed. Please refresh the page and try again.', 'rx-theme' );
	} else {
		/**
		 * Honeypot check.
		 * Real users should never fill this hidden field.
		 */
		$honeypot = isset( $_POST['rx_contact_website'] ) ? sanitize_text_field( wp_unslash( $_POST['rx_contact_website'] ) ) : '';

		if ( ! empty( $honeypot ) ) {
			$rx_contact_errors[] = __( 'Spam protection triggered. Please try again.', 'rx-theme' );
		}

		/**
		 * Simple rate limit.
		 */
		$client_ip      = rx_contact_get_client_ip();
		$rate_limit_key = 'rx_contact_rate_' . md5( $client_ip );
		$rate_count     = (int) get_transient( $rate_limit_key );
		$max_attempts   = (int) apply_filters( 'rx_theme_contact_rate_limit_max_attempts', 5 );
		$lock_time      = (int) apply_filters( 'rx_theme_contact_rate_limit_seconds', HOUR_IN_SECONDS );

		if ( $rate_count >= $max_attempts ) {
			$rx_contact_errors[] = __( 'Too many messages were submitted from your connection. Please try again later.', 'rx-theme' );
		}

		/**
		 * Sanitize fields.
		 */
		$rx_contact_values['name']    = isset( $_POST['rx_contact_name'] ) ? sanitize_text_field( wp_unslash( $_POST['rx_contact_name'] ) ) : '';
		$rx_contact_values['email']   = isset( $_POST['rx_contact_email'] ) ? sanitize_email( wp_unslash( $_POST['rx_contact_email'] ) ) : '';
		$rx_contact_values['phone']   = isset( $_POST['rx_contact_phone'] ) ? sanitize_text_field( wp_unslash( $_POST['rx_contact_phone'] ) ) : '';
		$rx_contact_values['subject'] = isset( $_POST['rx_contact_subject'] ) ? sanitize_text_field( wp_unslash( $_POST['rx_contact_subject'] ) ) : '';
		$rx_contact_values['type']    = isset( $_POST['rx_contact_type'] ) ? sanitize_text_field( wp_unslash( $_POST['rx_contact_type'] ) ) : '';
		$rx_contact_values['message'] = isset( $_POST['rx_contact_message'] ) ? sanitize_textarea_field( wp_unslash( $_POST['rx_contact_message'] ) ) : '';
		$rx_contact_values['privacy'] = isset( $_POST['rx_contact_privacy'] ) ? sanitize_text_field( wp_unslash( $_POST['rx_contact_privacy'] ) ) : '';

		/**
		 * Validation.
		 */
		if ( empty( $rx_contact_values['name'] ) ) {
			$rx_contact_errors[] = __( 'Please enter your name.', 'rx-theme' );
		}

		if ( strlen( $rx_contact_values['name'] ) > 80 ) {
			$rx_contact_errors[] = __( 'Name is too long.', 'rx-theme' );
		}

		if ( empty( $rx_contact_values['email'] ) || ! is_email( $rx_contact_values['email'] ) ) {
			$rx_contact_errors[] = __( 'Please enter a valid email address.', 'rx-theme' );
		}

		if ( ! empty( $rx_contact_values['phone'] ) && strlen( $rx_contact_values['phone'] ) > 30 ) {
			$rx_contact_errors[] = __( 'Phone number is too long.', 'rx-theme' );
		}

		if ( empty( $rx_contact_values['subject'] ) ) {
			$rx_contact_errors[] = __( 'Please enter a subject.', 'rx-theme' );
		}

		if ( strlen( $rx_contact_values['subject'] ) > 120 ) {
			$rx_contact_errors[] = __( 'Subject is too long.', 'rx-theme' );
		}

		if ( empty( $rx_contact_values['message'] ) ) {
			$rx_contact_errors[] = __( 'Please write your message.', 'rx-theme' );
		}

		if ( strlen( $rx_contact_values['message'] ) < 10 ) {
			$rx_contact_errors[] = __( 'Message is too short. Please write a little more detail.', 'rx-theme' );
		}

		if ( strlen( $rx_contact_values['message'] ) > 3000 ) {
			$rx_contact_errors[] = __( 'Message is too long. Please keep it under 3000 characters.', 'rx-theme' );
		}

		if ( 'yes' !== $rx_contact_values['privacy'] ) {
			$rx_contact_errors[] = __( 'Please agree to the privacy notice before sending your message.', 'rx-theme' );
		}

		/**
		 * Send email if valid.
		 */
		if ( empty( $rx_contact_errors ) ) {
			$to = apply_filters(
				'rx_theme_contact_recipient_email',
				! empty( $rx_contact_data['email'] ) ? $rx_contact_data['email'] : get_option( 'admin_email' )
			);

			$email_subject = sprintf(
				/* translators: %s: Contact form subject. */
				__( '[Contact Form] %s', 'rx-theme' ),
				$rx_contact_values['subject']
			);

			$email_subject = apply_filters( 'rx_theme_contact_email_subject', $email_subject, $rx_contact_values );

			$email_body  = "New contact message from RX Theme contact page\n\n";
			$email_body .= "Name: " . $rx_contact_values['name'] . "\n";
			$email_body .= "Email: " . $rx_contact_values['email'] . "\n";
			$email_body .= "Phone: " . $rx_contact_values['phone'] . "\n";
			$email_body .= "Message Type: " . $rx_contact_values['type'] . "\n";
			$email_body .= "Subject: " . $rx_contact_values['subject'] . "\n\n";
			$email_body .= "Message:\n" . $rx_contact_values['message'] . "\n\n";
			$email_body .= "Page: " . rx_contact_get_current_url() . "\n";
			$email_body .= "IP: " . $client_ip . "\n";
			$email_body .= "Time: " . current_time( 'mysql' ) . "\n";

			$email_body = apply_filters( 'rx_theme_contact_email_body', $email_body, $rx_contact_values );

			$headers = array(
				'Content-Type: text/plain; charset=UTF-8',
				'Reply-To: ' . $rx_contact_values['name'] . ' <' . $rx_contact_values['email'] . '>',
			);

			$headers = apply_filters( 'rx_theme_contact_email_headers', $headers, $rx_contact_values );

			$mail_sent = wp_mail( $to, $email_subject, $email_body, $headers );

			if ( $mail_sent ) {
				$rx_contact_success = true;
				$rx_contact_values  = array(
					'name'    => '',
					'email'   => '',
					'phone'   => '',
					'subject' => '',
					'type'    => '',
					'message' => '',
					'privacy' => '',
				);

				set_transient( $rate_limit_key, $rate_count + 1, $lock_time );

				do_action( 'rx_theme_contact_form_sent', $to, $email_subject, $email_body );
			} else {
				$rx_contact_errors[] = __( 'Message could not be sent. Please try again or contact us directly by phone/email.', 'rx-theme' );
			}
		} else {
			set_transient( $rate_limit_key, $rate_count + 1, $lock_time );
		}
	}
}

/**
 * ------------------------------------------------------------
 * SCHEMA DATA
 * ------------------------------------------------------------
 */

if ( ! function_exists( 'rx_contact_output_schema' ) ) {
	/**
	 * Output JSON-LD schema.
	 *
	 * @param array $data Contact data.
	 * @return void
	 */
	function rx_contact_output_schema( $data ) {
		$schema = array(
			'@context'    => 'https://schema.org',
			'@type'       => 'MedicalOrganization',
			'name'        => isset( $data['office_name'] ) ? wp_strip_all_tags( $data['office_name'] ) : get_bloginfo( 'name' ),
			'url'         => home_url( '/' ),
			'email'       => isset( $data['email'] ) ? sanitize_email( $data['email'] ) : '',
			'telephone'   => isset( $data['phone'] ) ? sanitize_text_field( $data['phone'] ) : '',
			'description' => get_bloginfo( 'description' ),
			'address'     => array(
				'@type'           => 'PostalAddress',
				'streetAddress'   => isset( $data['address'] ) ? wp_strip_all_tags( $data['address'] ) : '',
				'addressLocality' => isset( $data['city'] ) ? wp_strip_all_tags( $data['city'] ) : '',
				'addressCountry'  => isset( $data['country'] ) ? wp_strip_all_tags( $data['country'] ) : '',
			),
			'contactPoint' => array(
				array(
					'@type'       => 'ContactPoint',
					'telephone'   => isset( $data['phone'] ) ? sanitize_text_field( $data['phone'] ) : '',
					'contactType' => 'customer support',
					'areaServed'  => isset( $data['country'] ) ? wp_strip_all_tags( $data['country'] ) : '',
					'availableLanguage' => array( 'English', 'Bangla' ),
				),
			),
		);

		$schema = apply_filters( 'rx_theme_contact_schema', $schema, $data );

		echo '<script type="application/ld+json">' . wp_json_encode( $schema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE ) . '</script>' . "\n";
	}
}

if ( ! empty( $rx_contact_data['enable_schema'] ) ) {
	rx_contact_output_schema( $rx_contact_data );
}

?>

<main id="primary" class="rx-site-main rx-contact-template" role="main">

	<?php do_action( 'rx_theme_before_contact_template' ); ?>

	<section class="rx-contact-hero" aria-labelledby="rx-contact-title">
		<div class="rx-container">
			<div class="rx-contact-hero__inner">

				<?php if ( ! empty( $rx_contact_data['hero_kicker'] ) ) : ?>
					<p class="rx-contact-hero__kicker">
						<?php echo esc_html( $rx_contact_data['hero_kicker'] ); ?>
					</p>
				<?php endif; ?>

				<h1 id="rx-contact-title" class="rx-contact-hero__title">
					<?php echo esc_html( $rx_contact_data['hero_title'] ); ?>
				</h1>

				<?php if ( ! empty( $rx_contact_data['hero_description'] ) ) : ?>
					<div class="rx-contact-hero__description">
						<?php echo wp_kses( wpautop( $rx_contact_data['hero_description'] ), rx_contact_allowed_html() ); ?>
					</div>
				<?php endif; ?>

				<div class="rx-contact-hero__actions">
					<?php if ( ! empty( $rx_contact_data['phone'] ) ) : ?>
						<a class="rx-btn rx-btn--primary" href="tel:<?php echo esc_attr( rx_contact_clean_phone( $rx_contact_data['phone'] ) ); ?>">
							<?php esc_html_e( 'Call Now', 'rx-theme' ); ?>
						</a>
					<?php endif; ?>

					<?php if ( ! empty( $rx_contact_data['email'] ) ) : ?>
						<a class="rx-btn rx-btn--outline" href="mailto:<?php echo esc_attr( antispambot( $rx_contact_data['email'] ) ); ?>">
							<?php esc_html_e( 'Email Us', 'rx-theme' ); ?>
						</a>
					<?php endif; ?>
				</div>

			</div>
		</div>
	</section>

	<?php if ( ! empty( $rx_contact_data['enable_emergency'] ) ) : ?>
		<section class="rx-contact-alert" aria-label="<?php esc_attr_e( 'Emergency notice', 'rx-theme' ); ?>">
			<div class="rx-container">
				<div class="rx-contact-alert__box">
					<strong><?php esc_html_e( 'Emergency Notice:', 'rx-theme' ); ?></strong>
					<span>
						<?php esc_html_e( 'If you have severe symptoms or a medical emergency, do not wait for an online reply. Call emergency medical services or visit the nearest hospital immediately.', 'rx-theme' ); ?>
					</span>

					<?php if ( ! empty( $rx_contact_data['emergency_phone'] ) ) : ?>
						<a href="tel:<?php echo esc_attr( rx_contact_clean_phone( $rx_contact_data['emergency_phone'] ) ); ?>">
							<?php echo esc_html( $rx_contact_data['emergency_phone'] ); ?>
						</a>
					<?php endif; ?>
				</div>
			</div>
		</section>
	<?php endif; ?>

	<section class="rx-contact-main-section">
		<div class="rx-container">
			<div class="rx-contact-grid">

				<aside class="rx-contact-sidebar" aria-label="<?php esc_attr_e( 'Contact information', 'rx-theme' ); ?>">

					<div class="rx-contact-card">
						<h2 class="rx-contact-card__title">
							<?php esc_html_e( 'Contact Information', 'rx-theme' ); ?>
						</h2>

						<ul class="rx-contact-list">
							<?php if ( ! empty( $rx_contact_data['office_name'] ) ) : ?>
								<li class="rx-contact-list__item">
									<span class="rx-contact-list__icon" aria-hidden="true">🏥</span>
									<span class="rx-contact-list__content">
										<strong><?php esc_html_e( 'Office', 'rx-theme' ); ?></strong>
										<span><?php echo esc_html( $rx_contact_data['office_name'] ); ?></span>
									</span>
								</li>
							<?php endif; ?>

							<?php if ( ! empty( $rx_contact_data['doctor_name'] ) ) : ?>
								<li class="rx-contact-list__item">
									<span class="rx-contact-list__icon" aria-hidden="true">👨‍⚕️</span>
									<span class="rx-contact-list__content">
										<strong><?php esc_html_e( 'Doctor / Team', 'rx-theme' ); ?></strong>
										<span><?php echo esc_html( $rx_contact_data['doctor_name'] ); ?></span>
									</span>
								</li>
							<?php endif; ?>

							<?php if ( ! empty( $rx_contact_data['phone'] ) ) : ?>
								<li class="rx-contact-list__item">
									<span class="rx-contact-list__icon" aria-hidden="true">📞</span>
									<span class="rx-contact-list__content">
										<strong><?php esc_html_e( 'Phone', 'rx-theme' ); ?></strong>
										<a href="tel:<?php echo esc_attr( rx_contact_clean_phone( $rx_contact_data['phone'] ) ); ?>">
											<?php echo esc_html( $rx_contact_data['phone'] ); ?>
										</a>
									</span>
								</li>
							<?php endif; ?>

							<?php if ( ! empty( $rx_contact_data['email'] ) ) : ?>
								<li class="rx-contact-list__item">
									<span class="rx-contact-list__icon" aria-hidden="true">✉️</span>
									<span class="rx-contact-list__content">
										<strong><?php esc_html_e( 'Email', 'rx-theme' ); ?></strong>
										<a href="mailto:<?php echo esc_attr( antispambot( $rx_contact_data['email'] ) ); ?>">
											<?php echo esc_html( antispambot( $rx_contact_data['email'] ) ); ?>
										</a>
									</span>
								</li>
							<?php endif; ?>

							<?php if ( ! empty( $rx_contact_data['address'] ) ) : ?>
								<li class="rx-contact-list__item">
									<span class="rx-contact-list__icon" aria-hidden="true">📍</span>
									<span class="rx-contact-list__content">
										<strong><?php esc_html_e( 'Address', 'rx-theme' ); ?></strong>
										<span><?php echo esc_html( $rx_contact_data['address'] ); ?></span>
									</span>
								</li>
							<?php endif; ?>
						</ul>
					</div>

					<div class="rx-contact-card">
						<h2 class="rx-contact-card__title">
							<?php esc_html_e( 'Opening Hours', 'rx-theme' ); ?>
						</h2>

						<div class="rx-contact-hours">
							<?php if ( ! empty( $rx_contact_data['hospital_hours'] ) ) : ?>
								<p>
									<strong><?php esc_html_e( 'Hospital:', 'rx-theme' ); ?></strong>
									<?php echo esc_html( $rx_contact_data['hospital_hours'] ); ?>
								</p>
							<?php endif; ?>

							<?php if ( ! empty( $rx_contact_data['chamber_hours'] ) ) : ?>
								<p>
									<strong><?php esc_html_e( 'Chamber:', 'rx-theme' ); ?></strong>
									<?php echo esc_html( $rx_contact_data['chamber_hours'] ); ?>
								</p>
							<?php endif; ?>

							<?php if ( ! empty( $rx_contact_data['weekly_off'] ) ) : ?>
								<p class="rx-contact-hours__note">
									<?php echo esc_html( $rx_contact_data['weekly_off'] ); ?>
								</p>
							<?php endif; ?>
						</div>
					</div>

					<?php
					$social_links = array(
						'facebook'  => array(
							'label' => __( 'Facebook', 'rx-theme' ),
							'url'   => $rx_contact_data['facebook'],
						),
						'youtube'   => array(
							'label' => __( 'YouTube', 'rx-theme' ),
							'url'   => $rx_contact_data['youtube'],
						),
						'linkedin'  => array(
							'label' => __( 'LinkedIn', 'rx-theme' ),
							'url'   => $rx_contact_data['linkedin'],
						),
						'x_twitter' => array(
							'label' => __( 'X / Twitter', 'rx-theme' ),
							'url'   => $rx_contact_data['x_twitter'],
						),
					);

					$social_links = apply_filters( 'rx_theme_contact_social_links', $social_links );
					$has_social   = false;

					foreach ( $social_links as $social ) {
						if ( ! empty( $social['url'] ) ) {
							$has_social = true;
							break;
						}
					}
					?>

					<?php if ( $has_social ) : ?>
						<div class="rx-contact-card">
							<h2 class="rx-contact-card__title">
								<?php esc_html_e( 'Follow Us', 'rx-theme' ); ?>
							</h2>

							<ul class="rx-contact-social">
								<?php foreach ( $social_links as $social ) : ?>
									<?php if ( ! empty( $social['url'] ) ) : ?>
										<li>
											<a href="<?php echo esc_url( $social['url'] ); ?>" target="_blank" rel="noopener noreferrer">
												<?php echo esc_html( $social['label'] ); ?>
											</a>
										</li>
									<?php endif; ?>
								<?php endforeach; ?>
							</ul>
						</div>
					<?php endif; ?>

					<?php do_action( 'rx_theme_contact_sidebar_after', $rx_contact_data ); ?>

				</aside>

				<div class="rx-contact-content">

					<?php if ( have_posts() ) : ?>
						<?php
						while ( have_posts() ) :
							the_post();
							?>
							<?php if ( trim( get_the_content() ) ) : ?>
								<article id="post-<?php the_ID(); ?>" <?php post_class( 'rx-contact-page-content' ); ?>>
									<div class="rx-entry-content">
										<?php
										the_content();

										wp_link_pages(
											array(
												'before' => '<div class="rx-page-links">' . esc_html__( 'Pages:', 'rx-theme' ),
												'after'  => '</div>',
											)
										);
										?>
									</div>
								</article>
							<?php endif; ?>
						<?php endwhile; ?>
					<?php endif; ?>

					<?php if ( ! empty( $rx_contact_data['enable_form'] ) ) : ?>
						<section class="rx-contact-form-section" aria-labelledby="rx-contact-form-title">

							<div class="rx-section-heading">
								<p class="rx-section-heading__kicker">
									<?php esc_html_e( 'Send Message', 'rx-theme' ); ?>
								</p>
								<h2 id="rx-contact-form-title" class="rx-section-heading__title">
									<?php esc_html_e( 'Write to Us', 'rx-theme' ); ?>
								</h2>
								<p class="rx-section-heading__description">
									<?php esc_html_e( 'Please fill out the form below. For urgent medical conditions, call directly or visit a hospital.', 'rx-theme' ); ?>
								</p>
							</div>

							<?php if ( $rx_contact_success ) : ?>
								<div class="rx-notice rx-notice--success" role="status" aria-live="polite">
									<strong><?php esc_html_e( 'Message sent successfully.', 'rx-theme' ); ?></strong>
									<span><?php esc_html_e( 'Thank you for contacting us. We will reply as soon as possible.', 'rx-theme' ); ?></span>
								</div>
							<?php endif; ?>

							<?php if ( ! empty( $rx_contact_errors ) ) : ?>
								<div class="rx-notice rx-notice--error" role="alert" aria-live="assertive">
									<strong><?php esc_html_e( 'Please fix the following:', 'rx-theme' ); ?></strong>
									<ul>
										<?php foreach ( $rx_contact_errors as $error ) : ?>
											<li><?php echo esc_html( $error ); ?></li>
										<?php endforeach; ?>
									</ul>
								</div>
							<?php endif; ?>

							<form class="rx-contact-form" method="post" action="<?php echo esc_url( get_permalink() ); ?>#rx-contact-form-title" novalidate>
								<?php wp_nonce_field( 'rx_contact_form_action', 'rx_contact_nonce' ); ?>

								<input type="hidden" name="rx_contact_form_submitted" value="1">

								<div class="rx-form-honeypot" aria-hidden="true">
									<label for="rx-contact-website">
										<?php esc_html_e( 'Website', 'rx-theme' ); ?>
									</label>
									<input
										type="text"
										id="rx-contact-website"
										name="rx_contact_website"
										value=""
										tabindex="-1"
										autocomplete="off"
									>
								</div>

								<div class="rx-form-grid">
									<div class="rx-form-field">
										<label for="rx-contact-name">
											<?php esc_html_e( 'Full Name', 'rx-theme' ); ?>
											<span aria-hidden="true">*</span>
										</label>
										<input
											type="text"
											id="rx-contact-name"
											name="rx_contact_name"
											value="<?php echo esc_attr( $rx_contact_values['name'] ); ?>"
											placeholder="<?php esc_attr_e( 'Enter your full name', 'rx-theme' ); ?>"
											required
											autocomplete="name"
										>
									</div>

									<div class="rx-form-field">
										<label for="rx-contact-email">
											<?php esc_html_e( 'Email Address', 'rx-theme' ); ?>
											<span aria-hidden="true">*</span>
										</label>
										<input
											type="email"
											id="rx-contact-email"
											name="rx_contact_email"
											value="<?php echo esc_attr( $rx_contact_values['email'] ); ?>"
											placeholder="<?php esc_attr_e( 'example@email.com', 'rx-theme' ); ?>"
											required
											autocomplete="email"
										>
									</div>

									<div class="rx-form-field">
										<label for="rx-contact-phone">
											<?php esc_html_e( 'Phone Number', 'rx-theme' ); ?>
										</label>
										<input
											type="tel"
											id="rx-contact-phone"
											name="rx_contact_phone"
											value="<?php echo esc_attr( $rx_contact_values['phone'] ); ?>"
											placeholder="<?php esc_attr_e( '+880...', 'rx-theme' ); ?>"
											autocomplete="tel"
										>
									</div>

									<div class="rx-form-field">
										<label for="rx-contact-type">
											<?php esc_html_e( 'Message Type', 'rx-theme' ); ?>
										</label>
										<select id="rx-contact-type" name="rx_contact_type">
											<option value="">
												<?php esc_html_e( 'Select message type', 'rx-theme' ); ?>
											</option>
											<option value="appointment" <?php selected( $rx_contact_values['type'], 'appointment' ); ?>>
												<?php esc_html_e( 'Appointment Request', 'rx-theme' ); ?>
											</option>
											<option value="medical-question" <?php selected( $rx_contact_values['type'], 'medical-question' ); ?>>
												<?php esc_html_e( 'Medical Question', 'rx-theme' ); ?>
											</option>
											<option value="website-support" <?php selected( $rx_contact_values['type'], 'website-support' ); ?>>
												<?php esc_html_e( 'Website Support', 'rx-theme' ); ?>
											</option>
											<option value="article-correction" <?php selected( $rx_contact_values['type'], 'article-correction' ); ?>>
												<?php esc_html_e( 'Article Correction', 'rx-theme' ); ?>
											</option>
											<option value="partnership" <?php selected( $rx_contact_values['type'], 'partnership' ); ?>>
												<?php esc_html_e( 'Partnership / Collaboration', 'rx-theme' ); ?>
											</option>
											<option value="other" <?php selected( $rx_contact_values['type'], 'other' ); ?>>
												<?php esc_html_e( 'Other', 'rx-theme' ); ?>
											</option>
										</select>
									</div>
								</div>

								<div class="rx-form-field">
									<label for="rx-contact-subject">
										<?php esc_html_e( 'Subject', 'rx-theme' ); ?>
										<span aria-hidden="true">*</span>
									</label>
									<input
										type="text"
										id="rx-contact-subject"
										name="rx_contact_subject"
										value="<?php echo esc_attr( $rx_contact_values['subject'] ); ?>"
										placeholder="<?php esc_attr_e( 'Write a short subject', 'rx-theme' ); ?>"
										required
									>
								</div>

								<div class="rx-form-field">
									<label for="rx-contact-message">
										<?php esc_html_e( 'Message', 'rx-theme' ); ?>
										<span aria-hidden="true">*</span>
									</label>
									<textarea
										id="rx-contact-message"
										name="rx_contact_message"
										rows="8"
										placeholder="<?php esc_attr_e( 'Write your message with useful details...', 'rx-theme' ); ?>"
										required
									><?php echo esc_textarea( $rx_contact_values['message'] ); ?></textarea>
									<p class="rx-form-help">
										<?php esc_html_e( 'Please do not send highly sensitive personal medical data through this general contact form.', 'rx-theme' ); ?>
									</p>
								</div>

								<div class="rx-form-field rx-form-field--checkbox">
									<label>
										<input
											type="checkbox"
											name="rx_contact_privacy"
											value="yes"
											<?php checked( $rx_contact_values['privacy'], 'yes' ); ?>
											required
										>
										<span>
											<?php esc_html_e( 'I understand this form is for general communication and not for emergency medical care.', 'rx-theme' ); ?>
										</span>
									</label>
								</div>

								<div class="rx-form-actions">
									<button type="submit" class="rx-btn rx-btn--primary rx-contact-submit">
										<?php esc_html_e( 'Send Message', 'rx-theme' ); ?>
									</button>
								</div>
							</form>
						</section>
					<?php endif; ?>

				</div>
			</div>
		</div>
	</section>

	<?php if ( ! empty( $rx_contact_data['enable_map'] ) ) : ?>
		<section class="rx-contact-map-section" aria-labelledby="rx-contact-map-title">
			<div class="rx-container">
				<div class="rx-section-heading rx-section-heading--center">
					<p class="rx-section-heading__kicker">
						<?php esc_html_e( 'Location', 'rx-theme' ); ?>
					</p>
					<h2 id="rx-contact-map-title" class="rx-section-heading__title">
						<?php esc_html_e( 'Find Us on Map', 'rx-theme' ); ?>
					</h2>
					<p class="rx-section-heading__description">
						<?php echo esc_html( $rx_contact_data['address'] ); ?>
					</p>
				</div>

				<div class="rx-contact-map">
					<?php if ( ! empty( $rx_contact_data['map_embed'] ) ) : ?>
						<div class="rx-contact-map__embed">
							<?php
							echo wp_kses(
								$rx_contact_data['map_embed'],
								array(
									'iframe' => array(
										'src'             => array(),
										'width'           => array(),
										'height'          => array(),
										'style'           => array(),
										'allowfullscreen' => array(),
										'loading'         => array(),
										'referrerpolicy'  => array(),
										'title'           => array(),
									),
								)
							);
							?>
						</div>
					<?php else : ?>
						<div class="rx-contact-map__placeholder">
							<p><?php esc_html_e( 'Map embed code is not added yet.', 'rx-theme' ); ?></p>
							<?php if ( ! empty( $rx_contact_data['map_link'] ) && '#' !== $rx_contact_data['map_link'] ) : ?>
								<a class="rx-btn rx-btn--outline" href="<?php echo esc_url( $rx_contact_data['map_link'] ); ?>" target="_blank" rel="noopener noreferrer">
									<?php esc_html_e( 'Open Map', 'rx-theme' ); ?>
								</a>
							<?php endif; ?>
						</div>
					<?php endif; ?>
				</div>
			</div>
		</section>
	<?php endif; ?>

	<?php if ( ! empty( $rx_contact_data['enable_faq'] ) ) : ?>
		<?php
		$rx_contact_faqs = apply_filters(
			'rx_theme_contact_faqs',
			array(
				array(
					'question' => __( 'Can I book an appointment through this contact form?', 'rx-theme' ),
					'answer'   => __( 'Yes, you can send an appointment request through the form. Please include your name, phone number, preferred time, and short reason for visit. Appointment confirmation may require phone communication.', 'rx-theme' ),
				),
				array(
					'question' => __( 'Can I send emergency medical questions here?', 'rx-theme' ),
					'answer'   => __( 'No. This contact form is not suitable for emergencies. If symptoms are severe, sudden, or dangerous, please visit the nearest emergency department or call emergency medical services immediately.', 'rx-theme' ),
				),
				array(
					'question' => __( 'How soon will I receive a reply?', 'rx-theme' ),
					'answer'   => __( 'Reply time depends on workload, hospital hours, chamber schedule, and message priority. For faster communication, please call the listed phone number.', 'rx-theme' ),
				),
				array(
					'question' => __( 'Can I report a mistake in a medical article?', 'rx-theme' ),
					'answer'   => __( 'Yes. Please select Article Correction as message type and share the article URL, the incorrect sentence, and the corrected evidence-based information if available.', 'rx-theme' ),
				),
			)
		);
		?>

		<section class="rx-contact-faq-section" aria-labelledby="rx-contact-faq-title">
			<div class="rx-container">
				<div class="rx-section-heading rx-section-heading--center">
					<p class="rx-section-heading__kicker">
						<?php esc_html_e( 'Questions', 'rx-theme' ); ?>
					</p>
					<h2 id="rx-contact-faq-title" class="rx-section-heading__title">
						<?php esc_html_e( 'Contact FAQs', 'rx-theme' ); ?>
					</h2>
				</div>

				<div class="rx-contact-faq">
					<?php foreach ( $rx_contact_faqs as $index => $faq ) : ?>
						<details class="rx-contact-faq__item" <?php echo 0 === (int) $index ? 'open' : ''; ?>>
							<summary class="rx-contact-faq__question">
								<?php echo esc_html( $faq['question'] ); ?>
							</summary>
							<div class="rx-contact-faq__answer">
								<?php echo wp_kses( wpautop( $faq['answer'] ), rx_contact_allowed_html() ); ?>
							</div>
						</details>
					<?php endforeach; ?>
				</div>
			</div>
		</section>
	<?php endif; ?>

	<?php do_action( 'rx_theme_after_contact_template', $rx_contact_data ); ?>

</main>

<?php
get_footer();

For best result, add this page template from WordPress admin:

Pages → Add New/Edit Contact Page → Template → RX Contact Page → Update

Then later you can control the values through Customizer using theme mods like:

rx_contact_phone
rx_contact_email
rx_contact_address
rx_contact_hospital_hours
rx_contact_chamber_hours
rx_contact_map_embed
rx_contact_facebook
rx_contact_youtube
rx_contact_linkedin

This template is already advanced enough to work now, and later you can connect it with your RX Theme Customizer, REST API, SMTP plugin, admin settings page, or Gutenberg blocks.

Leave a Reply

Your email address will not be published. Required fields are marked *