I’ll build this as a full reusable RX Theme block template: safe data handling, variants, severity levels, icons, schema-friendly markup, accessibility, hooks, filters, and fallback defaults.
I found the key WordPress-safe pattern: this file should accept $args, escape output, and expose RX-prefixed filters/actions so you can extend it later without editing the block each time
Dear friend, create this file:
/template-parts/blocks/block-medical-note.php
This block is built for RX Theme as a reusable medical note component. It supports $args, post meta fallback, ACF fallback, severity types, icons, CTA, references, key points, disclaimer, review info, accessibility, JSON-LD, filters, hooks, collapsible UI, dismissible UI, and one-time CSS/JS output. WordPress officially supports reusable template parts through get_template_part(), post metadata through get_post_meta(), and extensibility through apply_filters() / do_action().
<?php
/**
* RX Theme - Advanced Medical Note Block
*
* File: /template-parts/blocks/block-medical-note.php
*
* Usage:
* get_template_part(
* 'template-parts/blocks/block',
* 'medical-note',
* array(
* 'type' => 'warning',
* 'title' => 'Important Medical Note',
* 'content' => 'This information is for education only.',
* 'key_points' => array( 'Seek medical help if symptoms worsen.' ),
* 'evidence_level' => 'General clinical guidance',
* 'reviewer' => 'Dr. RX Harun',
* 'reviewed_date' => '2026-05-16',
* 'source_url' => 'https://example.com',
* 'source_label' => 'Clinical source',
* 'cta_label' => 'Read full guide',
* 'cta_url' => home_url( '/medical-guides/' ),
* 'dismissible' => true,
* 'collapsible' => false,
* )
* );
*
* Post meta fallback examples:
* _rx_medical_note_enabled
* _rx_medical_note_type
* _rx_medical_note_title
* _rx_medical_note_content
* _rx_medical_note_key_points
* _rx_medical_note_evidence_level
* _rx_medical_note_reviewer
* _rx_medical_note_reviewed_date
* _rx_medical_note_source_url
* _rx_medical_note_source_label
* _rx_medical_note_cta_label
* _rx_medical_note_cta_url
*
* @package RX_Theme
*/
defined( 'ABSPATH' ) || exit;
/**
* --------------------------------------------------------------------------
* Local helpers
* --------------------------------------------------------------------------
* These closures avoid global function pollution and prevent redeclare errors
* when the template part is loaded multiple times.
*/
$rx_medical_note_get = static function ( $array, $key, $default = null ) {
if ( is_array( $array ) && array_key_exists( $key, $array ) ) {
return $array[ $key ];
}
return $default;
};
$rx_medical_note_bool = static function ( $value, $default = false ) {
if ( is_bool( $value ) ) {
return $value;
}
if ( is_numeric( $value ) ) {
return (bool) $value;
}
if ( is_string( $value ) ) {
$value = strtolower( trim( $value ) );
if ( in_array( $value, array( '1', 'true', 'yes', 'on', 'enabled', 'show' ), true ) ) {
return true;
}
if ( in_array( $value, array( '0', 'false', 'no', 'off', 'disabled', 'hide' ), true ) ) {
return false;
}
}
return (bool) $default;
};
$rx_medical_note_to_array = static function ( $value ) {
if ( empty( $value ) ) {
return array();
}
if ( is_array( $value ) ) {
return array_values( array_filter( $value ) );
}
if ( is_string( $value ) ) {
$decoded = json_decode( $value, true );
if ( is_array( $decoded ) ) {
return array_values( array_filter( $decoded ) );
}
$lines = preg_split( '/\r\n|\r|\n|,/', $value );
return array_values(
array_filter(
array_map(
static function ( $item ) {
return trim( wp_strip_all_tags( (string) $item ) );
},
(array) $lines
)
)
);
}
return array();
};
$rx_medical_note_acf = static function ( $field, $default = '' ) {
if ( function_exists( 'get_field' ) ) {
$value = get_field( $field );
if ( null !== $value && '' !== $value && false !== $value ) {
return $value;
}
}
return $default;
};
$rx_medical_note_meta = static function ( $key, $default = '' ) use ( $rx_medical_note_acf ) {
$post_id = get_the_ID();
if ( ! $post_id ) {
return $rx_medical_note_acf( $key, $default );
}
$value = get_post_meta( $post_id, $key, true );
if ( '' !== $value && null !== $value ) {
return $value;
}
return $rx_medical_note_acf( ltrim( $key, '_' ), $default );
};
$rx_medical_note_clean_id = static function ( $value, $fallback = '' ) {
$value = is_string( $value ) ? $value : '';
$value = preg_replace( '/[^A-Za-z0-9\-_:.]/', '-', $value );
$value = trim( $value, '-' );
if ( '' === $value ) {
$value = $fallback;
}
return $value;
};
/**
* --------------------------------------------------------------------------
* Defaults
* --------------------------------------------------------------------------
*/
$rx_medical_note_default_args = array(
'enabled' => $rx_medical_note_bool( $rx_medical_note_meta( '_rx_medical_note_enabled', true ), true ),
'id' => '',
'type' => $rx_medical_note_meta( '_rx_medical_note_type', 'info' ),
'style' => 'boxed',
'size' => 'normal',
'align' => 'none',
'title' => $rx_medical_note_meta( '_rx_medical_note_title', __( 'Medical Note', 'rx-theme' ) ),
'subtitle' => $rx_medical_note_meta( '_rx_medical_note_subtitle', '' ),
'content' => $rx_medical_note_meta( '_rx_medical_note_content', '' ),
'summary' => $rx_medical_note_meta( '_rx_medical_note_summary', '' ),
'icon' => '',
'show_icon' => true,
'show_badge' => true,
'badge_text' => '',
'key_points' => $rx_medical_note_to_array( $rx_medical_note_meta( '_rx_medical_note_key_points', '' ) ),
'warning_signs' => $rx_medical_note_to_array( $rx_medical_note_meta( '_rx_medical_note_warning_signs', '' ) ),
'do_list' => $rx_medical_note_to_array( $rx_medical_note_meta( '_rx_medical_note_do_list', '' ) ),
'dont_list' => $rx_medical_note_to_array( $rx_medical_note_meta( '_rx_medical_note_dont_list', '' ) ),
'evidence_level' => $rx_medical_note_meta( '_rx_medical_note_evidence_level', '' ),
'reviewer' => $rx_medical_note_meta( '_rx_medical_note_reviewer', '' ),
'reviewer_url' => $rx_medical_note_meta( '_rx_medical_note_reviewer_url', '' ),
'reviewed_date' => $rx_medical_note_meta( '_rx_medical_note_reviewed_date', '' ),
'updated_date' => $rx_medical_note_meta( '_rx_medical_note_updated_date', '' ),
'source_url' => $rx_medical_note_meta( '_rx_medical_note_source_url', '' ),
'source_label' => $rx_medical_note_meta( '_rx_medical_note_source_label', '' ),
'secondary_source_url' => $rx_medical_note_meta( '_rx_medical_note_secondary_source_url', '' ),
'secondary_source_label' => $rx_medical_note_meta( '_rx_medical_note_secondary_source_label', '' ),
'cta_label' => $rx_medical_note_meta( '_rx_medical_note_cta_label', '' ),
'cta_url' => $rx_medical_note_meta( '_rx_medical_note_cta_url', '' ),
'cta_target' => '_self',
'disclaimer' => $rx_medical_note_meta(
'_rx_medical_note_disclaimer',
__( 'This information is for general education only and does not replace professional medical advice, diagnosis, or treatment.', 'rx-theme' )
),
'show_disclaimer' => true,
'dismissible' => false,
'collapsible' => false,
'default_open' => true,
'print_schema' => true,
'print_assets' => true,
'extra_class' => '',
'attributes' => array(),
);
/**
* Allow parent templates, plugins, or child themes to modify defaults.
*/
$rx_medical_note_default_args = apply_filters(
'rx_theme_medical_note_default_args',
$rx_medical_note_default_args
);
$args = isset( $args ) && is_array( $args ) ? $args : array();
$rx_medical_note_args = wp_parse_args( $args, $rx_medical_note_default_args );
/**
* Final filter for all data.
*/
$rx_medical_note_args = apply_filters(
'rx_theme_medical_note_args',
$rx_medical_note_args,
get_the_ID()
);
/**
* --------------------------------------------------------------------------
* Normalize values
* --------------------------------------------------------------------------
*/
$rx_medical_note_enabled = $rx_medical_note_bool( $rx_medical_note_get( $rx_medical_note_args, 'enabled', true ), true );
if ( ! $rx_medical_note_enabled ) {
return;
}
$rx_medical_note_allowed_types = apply_filters(
'rx_theme_medical_note_allowed_types',
array(
'info',
'success',
'warning',
'danger',
'emergency',
'tip',
'clinical',
'diagnosis',
'treatment',
'dosage',
'contraindication',
'reference',
'research',
'editorial',
'doctor',
'patient',
'seo',
)
);
$rx_medical_note_type = sanitize_key( (string) $rx_medical_note_get( $rx_medical_note_args, 'type', 'info' ) );
if ( ! in_array( $rx_medical_note_type, $rx_medical_note_allowed_types, true ) ) {
$rx_medical_note_type = 'info';
}
$rx_medical_note_style = sanitize_key( (string) $rx_medical_note_get( $rx_medical_note_args, 'style', 'boxed' ) );
$rx_medical_note_size = sanitize_key( (string) $rx_medical_note_get( $rx_medical_note_args, 'size', 'normal' ) );
$rx_medical_note_align = sanitize_key( (string) $rx_medical_note_get( $rx_medical_note_args, 'align', 'none' ) );
$rx_medical_note_title = (string) $rx_medical_note_get( $rx_medical_note_args, 'title', '' );
$rx_medical_note_subtitle = (string) $rx_medical_note_get( $rx_medical_note_args, 'subtitle', '' );
$rx_medical_note_content = (string) $rx_medical_note_get( $rx_medical_note_args, 'content', '' );
$rx_medical_note_summary = (string) $rx_medical_note_get( $rx_medical_note_args, 'summary', '' );
$rx_medical_note_key_points = $rx_medical_note_to_array( $rx_medical_note_get( $rx_medical_note_args, 'key_points', array() ) );
$rx_medical_note_warning_signs = $rx_medical_note_to_array( $rx_medical_note_get( $rx_medical_note_args, 'warning_signs', array() ) );
$rx_medical_note_do_list = $rx_medical_note_to_array( $rx_medical_note_get( $rx_medical_note_args, 'do_list', array() ) );
$rx_medical_note_dont_list = $rx_medical_note_to_array( $rx_medical_note_get( $rx_medical_note_args, 'dont_list', array() ) );
$rx_medical_note_evidence_level = (string) $rx_medical_note_get( $rx_medical_note_args, 'evidence_level', '' );
$rx_medical_note_reviewer = (string) $rx_medical_note_get( $rx_medical_note_args, 'reviewer', '' );
$rx_medical_note_reviewer_url = (string) $rx_medical_note_get( $rx_medical_note_args, 'reviewer_url', '' );
$rx_medical_note_reviewed_date = (string) $rx_medical_note_get( $rx_medical_note_args, 'reviewed_date', '' );
$rx_medical_note_updated_date = (string) $rx_medical_note_get( $rx_medical_note_args, 'updated_date', '' );
$rx_medical_note_source_url = (string) $rx_medical_note_get( $rx_medical_note_args, 'source_url', '' );
$rx_medical_note_source_label = (string) $rx_medical_note_get( $rx_medical_note_args, 'source_label', __( 'Reference', 'rx-theme' ) );
$rx_medical_note_source_url_2 = (string) $rx_medical_note_get( $rx_medical_note_args, 'secondary_source_url', '' );
$rx_medical_note_source_label_2 = (string) $rx_medical_note_get( $rx_medical_note_args, 'secondary_source_label', __( 'Additional reference', 'rx-theme' ) );
$rx_medical_note_cta_label = (string) $rx_medical_note_get( $rx_medical_note_args, 'cta_label', '' );
$rx_medical_note_cta_url = (string) $rx_medical_note_get( $rx_medical_note_args, 'cta_url', '' );
$rx_medical_note_cta_target = (string) $rx_medical_note_get( $rx_medical_note_args, 'cta_target', '_self' );
$rx_medical_note_disclaimer = (string) $rx_medical_note_get( $rx_medical_note_args, 'disclaimer', '' );
$rx_medical_note_show_disclaimer = $rx_medical_note_bool( $rx_medical_note_get( $rx_medical_note_args, 'show_disclaimer', true ), true );
$rx_medical_note_show_icon = $rx_medical_note_bool( $rx_medical_note_get( $rx_medical_note_args, 'show_icon', true ), true );
$rx_medical_note_show_badge = $rx_medical_note_bool( $rx_medical_note_get( $rx_medical_note_args, 'show_badge', true ), true );
$rx_medical_note_dismissible = $rx_medical_note_bool( $rx_medical_note_get( $rx_medical_note_args, 'dismissible', false ), false );
$rx_medical_note_collapsible = $rx_medical_note_bool( $rx_medical_note_get( $rx_medical_note_args, 'collapsible', false ), false );
$rx_medical_note_default_open = $rx_medical_note_bool( $rx_medical_note_get( $rx_medical_note_args, 'default_open', true ), true );
$rx_medical_note_print_schema = $rx_medical_note_bool( $rx_medical_note_get( $rx_medical_note_args, 'print_schema', true ), true );
$rx_medical_note_print_assets = $rx_medical_note_bool( $rx_medical_note_get( $rx_medical_note_args, 'print_assets', true ), true );
$rx_medical_note_extra_class = sanitize_html_class( (string) $rx_medical_note_get( $rx_medical_note_args, 'extra_class', '' ) );
$rx_medical_note_id = $rx_medical_note_clean_id(
(string) $rx_medical_note_get( $rx_medical_note_args, 'id', '' ),
function_exists( 'wp_unique_id' ) ? wp_unique_id( 'rx-medical-note-' ) : 'rx-medical-note-' . wp_rand( 1000, 9999 )
);
$rx_medical_note_heading_id = $rx_medical_note_id . '-heading';
$rx_medical_note_body_id = $rx_medical_note_id . '-body';
if (
'' === trim( wp_strip_all_tags( $rx_medical_note_title ) ) &&
'' === trim( wp_strip_all_tags( $rx_medical_note_content ) ) &&
empty( $rx_medical_note_key_points ) &&
empty( $rx_medical_note_warning_signs ) &&
empty( $rx_medical_note_do_list ) &&
empty( $rx_medical_note_dont_list )
) {
return;
}
/**
* --------------------------------------------------------------------------
* Badge map
* --------------------------------------------------------------------------
*/
$rx_medical_note_badge_map = apply_filters(
'rx_theme_medical_note_badge_map',
array(
'info' => __( 'Medical note', 'rx-theme' ),
'success' => __( 'Helpful note', 'rx-theme' ),
'warning' => __( 'Caution', 'rx-theme' ),
'danger' => __( 'Important warning', 'rx-theme' ),
'emergency' => __( 'Emergency warning', 'rx-theme' ),
'tip' => __( 'Clinical tip', 'rx-theme' ),
'clinical' => __( 'Clinical note', 'rx-theme' ),
'diagnosis' => __( 'Diagnosis note', 'rx-theme' ),
'treatment' => __( 'Treatment note', 'rx-theme' ),
'dosage' => __( 'Dosage note', 'rx-theme' ),
'contraindication' => __( 'Contraindication', 'rx-theme' ),
'reference' => __( 'Reference note', 'rx-theme' ),
'research' => __( 'Research note', 'rx-theme' ),
'editorial' => __( 'Editorial note', 'rx-theme' ),
'doctor' => __( 'Doctor note', 'rx-theme' ),
'patient' => __( 'Patient note', 'rx-theme' ),
'seo' => __( 'RX SEO note', 'rx-theme' ),
)
);
$rx_medical_note_badge_text = (string) $rx_medical_note_get( $rx_medical_note_args, 'badge_text', '' );
if ( '' === $rx_medical_note_badge_text ) {
$rx_medical_note_badge_text = isset( $rx_medical_note_badge_map[ $rx_medical_note_type ] )
? $rx_medical_note_badge_map[ $rx_medical_note_type ]
: __( 'Medical note', 'rx-theme' );
}
/**
* --------------------------------------------------------------------------
* Icon map
* --------------------------------------------------------------------------
*/
$rx_medical_note_icon_map = apply_filters(
'rx_theme_medical_note_icon_map',
array(
'info' => '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M11 17h2v-6h-2v6Zm1-8.25a1.25 1.25 0 1 0 0-2.5 1.25 1.25 0 0 0 0 2.5ZM12 22a10 10 0 1 1 0-20 10 10 0 0 1 0 20Z"/></svg>',
'success' => '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m10.1 15.55 7.05-7.05 1.4 1.4-8.45 8.45-4.65-4.65 1.4-1.4 3.25 3.25ZM12 22a10 10 0 1 1 0-20 10 10 0 0 1 0 20Z"/></svg>',
'warning' => '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M1.75 21 12 3l10.25 18H1.75Zm10.25-3a1.15 1.15 0 1 0 0-2.3 1.15 1.15 0 0 0 0 2.3Zm-1-3.7h2V9h-2v5.3Z"/></svg>',
'danger' => '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M12 22a10 10 0 1 1 0-20 10 10 0 0 1 0 20Zm-1-6h2v2h-2v-2Zm0-10h2v8h-2V6Z"/></svg>',
'emergency' => '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M10.5 2h3v7.5H21v3h-7.5V20h-3v-7.5H3v-3h7.5V2Z"/></svg>',
'tip' => '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M9 21h6v-2H9v2Zm3-19a7 7 0 0 0-4 12.75V17h8v-2.25A7 7 0 0 0 12 2Z"/></svg>',
'clinical' => '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M10 3h4v4h4v4h-4v10h-4V11H6V7h4V3Z"/></svg>',
'diagnosis' => '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M9.5 3a6.5 6.5 0 0 1 5.15 10.45l4.45 4.45-1.4 1.4-4.45-4.45A6.5 6.5 0 1 1 9.5 3Zm0 2a4.5 4.5 0 1 0 0 9 4.5 4.5 0 0 0 0-9Z"/></svg>',
'treatment' => '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="m4.22 19.78 7.07-7.07-2-2-7.07 7.07a1.41 1.41 0 0 0 2 2Zm8.48-8.48 4.95-4.95a2.12 2.12 0 0 0-3-3L9.7 8.3l3 3Z"/></svg>',
'dosage' => '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M7 3h10v6l-3 3 3 3v6H7v-6l3-3-3-3V3Zm2 2v3.2l3 3 3-3V5H9Zm3 7.8-3 3V19h6v-3.2l-3-3Z"/></svg>',
'contraindication' => '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M12 2a10 10 0 1 1 0 20 10 10 0 0 1 0-20ZM5.8 7.2a8 8 0 0 0 11 11L5.8 7.2Zm12.4 9.6a8 8 0 0 0-11-11l11 11Z"/></svg>',
'reference' => '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M6 2h12a2 2 0 0 1 2 2v18l-8-3-8 3V4a2 2 0 0 1 2-2Zm0 17.1 6-2.25 6 2.25V4H6v15.1Z"/></svg>',
'research' => '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M9 2h6v2h-1v5.3l5.45 8.85A2.5 2.5 0 0 1 17.32 22H6.68a2.5 2.5 0 0 1-2.13-3.85L10 9.3V4H9V2Zm3 8-6 9.75c-.2.33.03.75.42.75h11.16c.39 0 .62-.42.42-.75L12 10Z"/></svg>',
'editorial' => '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M4 4h16v2H4V4Zm0 4h16v2H4V8Zm0 4h10v2H4v-2Zm0 4h16v2H4v-2Z"/></svg>',
'doctor' => '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M12 12a5 5 0 1 0 0-10 5 5 0 0 0 0 10Zm-8 9a8 8 0 0 1 16 0H4Zm7-5h2v2h2v2h-2v2h-2v-2H9v-2h2v-2Z"/></svg>',
'patient' => '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M12 12a4 4 0 1 0 0-8 4 4 0 0 0 0 8Zm-7 9a7 7 0 0 1 14 0H5Z"/></svg>',
'seo' => '<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M4 4h16v4H4V4Zm0 6h7v10H4V10Zm9 0h7v4h-7v-4Zm0 6h7v4h-7v-4Z"/></svg>',
)
);
$rx_medical_note_icon = (string) $rx_medical_note_get( $rx_medical_note_args, 'icon', '' );
if ( '' === $rx_medical_note_icon ) {
$rx_medical_note_icon = isset( $rx_medical_note_icon_map[ $rx_medical_note_type ] )
? $rx_medical_note_icon_map[ $rx_medical_note_type ]
: $rx_medical_note_icon_map['info'];
}
/**
* --------------------------------------------------------------------------
* Classes and attributes
* --------------------------------------------------------------------------
*/
$rx_medical_note_classes = array(
'rx-medical-note',
'rx-medical-note--' . $rx_medical_note_type,
'rx-medical-note--style-' . $rx_medical_note_style,
'rx-medical-note--size-' . $rx_medical_note_size,
'rx-medical-note--align-' . $rx_medical_note_align,
);
if ( $rx_medical_note_dismissible ) {
$rx_medical_note_classes[] = 'is-dismissible';
}
if ( $rx_medical_note_collapsible ) {
$rx_medical_note_classes[] = 'is-collapsible';
}
if ( $rx_medical_note_default_open ) {
$rx_medical_note_classes[] = 'is-open';
}
if ( '' !== $rx_medical_note_extra_class ) {
$rx_medical_note_classes[] = $rx_medical_note_extra_class;
}
$rx_medical_note_classes = apply_filters(
'rx_theme_medical_note_classes',
array_filter( array_map( 'sanitize_html_class', $rx_medical_note_classes ) ),
$rx_medical_note_args
);
$rx_medical_note_role = in_array( $rx_medical_note_type, array( 'warning', 'danger', 'emergency', 'contraindication' ), true ) ? 'alert' : 'note';
$rx_medical_note_attrs = array(
'id' => $rx_medical_note_id,
'class' => implode( ' ', $rx_medical_note_classes ),
'role' => $rx_medical_note_role,
'aria-labelledby' => $rx_medical_note_heading_id,
'data-rx-block' => 'medical-note',
'data-rx-type' => $rx_medical_note_type,
);
if ( $rx_medical_note_collapsible ) {
$rx_medical_note_attrs['data-rx-collapsible'] = 'true';
$rx_medical_note_attrs['data-rx-open'] = $rx_medical_note_default_open ? 'true' : 'false';
}
if ( $rx_medical_note_dismissible ) {
$rx_medical_note_attrs['data-rx-dismissible'] = 'true';
}
$rx_medical_note_custom_attrs = $rx_medical_note_get( $rx_medical_note_args, 'attributes', array() );
if ( is_array( $rx_medical_note_custom_attrs ) ) {
foreach ( $rx_medical_note_custom_attrs as $attr_key => $attr_value ) {
$attr_key = sanitize_key( (string) $attr_key );
if ( '' === $attr_key ) {
continue;
}
if ( false === strpos( $attr_key, 'data-' ) && false === strpos( $attr_key, 'aria-' ) ) {
continue;
}
$rx_medical_note_attrs[ $attr_key ] = is_scalar( $attr_value ) ? (string) $attr_value : wp_json_encode( $attr_value );
}
}
$rx_medical_note_attrs = apply_filters(
'rx_theme_medical_note_attributes',
$rx_medical_note_attrs,
$rx_medical_note_args
);
$rx_medical_note_attr_html = '';
foreach ( $rx_medical_note_attrs as $attr_key => $attr_value ) {
if ( null === $attr_value || false === $attr_value || '' === $attr_value ) {
continue;
}
$rx_medical_note_attr_html .= sprintf(
' %s="%s"',
esc_attr( $attr_key ),
esc_attr( (string) $attr_value )
);
}
/**
* --------------------------------------------------------------------------
* Schema data
* --------------------------------------------------------------------------
*/
$rx_medical_note_schema = array(
'@context' => 'https://schema.org',
'@type' => 'MedicalWebPage',
'name' => wp_strip_all_tags( $rx_medical_note_title ),
'description' => wp_strip_all_tags( $rx_medical_note_summary ? $rx_medical_note_summary : $rx_medical_note_content ),
);
if ( $rx_medical_note_reviewed_date ) {
$rx_medical_note_schema['reviewedBy'] = array(
'@type' => 'Person',
'name' => wp_strip_all_tags( $rx_medical_note_reviewer ? $rx_medical_note_reviewer : get_bloginfo( 'name' ) ),
);
$rx_medical_note_schema['dateReviewed'] = wp_strip_all_tags( $rx_medical_note_reviewed_date );
}
if ( $rx_medical_note_updated_date ) {
$rx_medical_note_schema['dateModified'] = wp_strip_all_tags( $rx_medical_note_updated_date );
}
if ( $rx_medical_note_source_url ) {
$rx_medical_note_schema['citation'] = esc_url_raw( $rx_medical_note_source_url );
}
$rx_medical_note_schema = apply_filters(
'rx_theme_medical_note_schema',
$rx_medical_note_schema,
$rx_medical_note_args
);
/**
* --------------------------------------------------------------------------
* One-time assets
* --------------------------------------------------------------------------
*/
static $rx_medical_note_assets_printed = false;
if ( $rx_medical_note_print_assets && ! $rx_medical_note_assets_printed ) :
$rx_medical_note_assets_printed = true;
?>
<style id="rx-medical-note-inline-css">
.rx-medical-note {
--rx-note-bg: #f8fafc;
--rx-note-border: #dbe3ea;
--rx-note-accent: #2563eb;
--rx-note-text: #102033;
--rx-note-muted: #536579;
--rx-note-soft: rgba(37, 99, 235, 0.08);
position: relative;
display: block;
margin: 1.5rem 0;
padding: 1rem;
color: var(--rx-note-text);
background: var(--rx-note-bg);
border: 1px solid var(--rx-note-border);
border-inline-start: 5px solid var(--rx-note-accent);
border-radius: 16px;
box-shadow: 0 8px 28px rgba(15, 23, 42, 0.06);
overflow: hidden;
}
.rx-medical-note--warning {
--rx-note-bg: #fffbeb;
--rx-note-border: #fde68a;
--rx-note-accent: #d97706;
--rx-note-soft: rgba(217, 119, 6, 0.1);
}
.rx-medical-note--danger,
.rx-medical-note--emergency,
.rx-medical-note--contraindication {
--rx-note-bg: #fff1f2;
--rx-note-border: #fecdd3;
--rx-note-accent: #e11d48;
--rx-note-soft: rgba(225, 29, 72, 0.1);
}
.rx-medical-note--success {
--rx-note-bg: #ecfdf5;
--rx-note-border: #bbf7d0;
--rx-note-accent: #059669;
--rx-note-soft: rgba(5, 150, 105, 0.1);
}
.rx-medical-note--clinical,
.rx-medical-note--doctor,
.rx-medical-note--diagnosis,
.rx-medical-note--treatment {
--rx-note-bg: #f0f9ff;
--rx-note-border: #bae6fd;
--rx-note-accent: #0284c7;
--rx-note-soft: rgba(2, 132, 199, 0.1);
}
.rx-medical-note--research,
.rx-medical-note--reference,
.rx-medical-note--editorial,
.rx-medical-note--seo {
--rx-note-bg: #f5f3ff;
--rx-note-border: #ddd6fe;
--rx-note-accent: #7c3aed;
--rx-note-soft: rgba(124, 58, 237, 0.1);
}
.rx-medical-note--tip,
.rx-medical-note--patient,
.rx-medical-note--dosage {
--rx-note-bg: #f0fdfa;
--rx-note-border: #99f6e4;
--rx-note-accent: #0f766e;
--rx-note-soft: rgba(15, 118, 110, 0.1);
}
.rx-medical-note--style-minimal {
box-shadow: none;
border-radius: 12px;
}
.rx-medical-note--style-card {
border-inline-start-width: 1px;
}
.rx-medical-note--size-small {
padding: 0.75rem;
font-size: 0.925rem;
}
.rx-medical-note--size-large {
padding: 1.25rem;
font-size: 1.05rem;
}
.rx-medical-note--align-center {
text-align: center;
}
.rx-medical-note__header {
display: flex;
gap: 0.875rem;
align-items: flex-start;
}
.rx-medical-note__icon {
display: inline-flex;
align-items: center;
justify-content: center;
flex: 0 0 auto;
width: 2.35rem;
height: 2.35rem;
color: var(--rx-note-accent);
background: var(--rx-note-soft);
border-radius: 999px;
}
.rx-medical-note__icon svg {
width: 1.25rem;
height: 1.25rem;
fill: currentColor;
}
.rx-medical-note__head-content {
min-width: 0;
flex: 1 1 auto;
}
.rx-medical-note__badge {
display: inline-flex;
align-items: center;
width: fit-content;
margin-bottom: 0.35rem;
padding: 0.2rem 0.55rem;
font-size: 0.75rem;
font-weight: 700;
line-height: 1.2;
letter-spacing: 0.02em;
color: var(--rx-note-accent);
background: var(--rx-note-soft);
border-radius: 999px;
text-transform: uppercase;
}
.rx-medical-note__title {
margin: 0;
font-size: clamp(1.05rem, 1vw + 0.9rem, 1.35rem);
line-height: 1.3;
font-weight: 800;
}
.rx-medical-note__subtitle {
margin: 0.35rem 0 0;
color: var(--rx-note-muted);
line-height: 1.6;
}
.rx-medical-note__body {
margin-top: 0.95rem;
}
.rx-medical-note__summary,
.rx-medical-note__content,
.rx-medical-note__disclaimer {
line-height: 1.75;
}
.rx-medical-note__summary {
margin-bottom: 0.75rem;
font-weight: 650;
}
.rx-medical-note__content > *:first-child,
.rx-medical-note__summary > *:first-child,
.rx-medical-note__disclaimer > *:first-child {
margin-top: 0;
}
.rx-medical-note__content > *:last-child,
.rx-medical-note__summary > *:last-child,
.rx-medical-note__disclaimer > *:last-child {
margin-bottom: 0;
}
.rx-medical-note__grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 0.75rem;
margin-top: 1rem;
}
.rx-medical-note__panel {
padding: 0.875rem;
background: rgba(255, 255, 255, 0.55);
border: 1px solid var(--rx-note-border);
border-radius: 12px;
}
.rx-medical-note__panel-title {
margin: 0 0 0.55rem;
font-size: 0.95rem;
font-weight: 800;
}
.rx-medical-note__list {
margin: 0;
padding-inline-start: 1.2rem;
}
.rx-medical-note__list li {
margin: 0.4rem 0;
line-height: 1.6;
}
.rx-medical-note__meta {
display: flex;
flex-wrap: wrap;
gap: 0.5rem;
margin-top: 1rem;
color: var(--rx-note-muted);
font-size: 0.875rem;
}
.rx-medical-note__meta-item {
display: inline-flex;
align-items: center;
gap: 0.35rem;
padding: 0.25rem 0.5rem;
background: rgba(255, 255, 255, 0.55);
border: 1px solid var(--rx-note-border);
border-radius: 999px;
}
.rx-medical-note__actions {
display: flex;
flex-wrap: wrap;
gap: 0.65rem;
margin-top: 1rem;
}
.rx-medical-note__link,
.rx-medical-note__cta {
color: var(--rx-note-accent);
font-weight: 700;
text-decoration-thickness: 0.12em;
text-underline-offset: 0.18em;
}
.rx-medical-note__cta {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 0.6rem 0.85rem;
color: #fff;
background: var(--rx-note-accent);
border-radius: 999px;
text-decoration: none;
}
.rx-medical-note__cta:focus-visible,
.rx-medical-note__link:focus-visible,
.rx-medical-note__dismiss:focus-visible,
.rx-medical-note__toggle:focus-visible {
outline: 3px solid var(--rx-note-accent);
outline-offset: 3px;
}
.rx-medical-note__disclaimer {
margin-top: 1rem;
padding: 0.75rem;
font-size: 0.9rem;
color: var(--rx-note-muted);
background: rgba(255, 255, 255, 0.45);
border-radius: 12px;
}
.rx-medical-note__dismiss,
.rx-medical-note__toggle {
position: absolute;
inset-block-start: 0.75rem;
inset-inline-end: 0.75rem;
display: inline-flex;
align-items: center;
justify-content: center;
width: 2rem;
height: 2rem;
color: var(--rx-note-muted);
background: rgba(255, 255, 255, 0.65);
border: 1px solid var(--rx-note-border);
border-radius: 999px;
cursor: pointer;
}
.rx-medical-note__toggle {
inset-inline-end: 3rem;
}
.rx-medical-note__dismiss:hover,
.rx-medical-note__toggle:hover {
color: var(--rx-note-accent);
}
.rx-medical-note.is-collapsible:not(.is-open) .rx-medical-note__body {
display: none;
}
.rx-medical-note.is-hidden {
display: none;
}
@media (max-width: 680px) {
.rx-medical-note {
border-radius: 14px;
}
.rx-medical-note__grid {
grid-template-columns: 1fr;
}
.rx-medical-note__header {
gap: 0.65rem;
}
.rx-medical-note__icon {
width: 2rem;
height: 2rem;
}
.rx-medical-note__toggle {
inset-inline-end: 2.85rem;
}
}
@media print {
.rx-medical-note {
box-shadow: none;
break-inside: avoid;
}
.rx-medical-note__dismiss,
.rx-medical-note__toggle {
display: none;
}
.rx-medical-note.is-collapsible .rx-medical-note__body {
display: block !important;
}
}
</style>
<script id="rx-medical-note-inline-js">
(function () {
'use strict';
function ready(callback) {
if (document.readyState !== 'loading') {
callback();
return;
}
document.addEventListener('DOMContentLoaded', callback);
}
ready(function () {
document.querySelectorAll('[data-rx-block="medical-note"]').forEach(function (note) {
var dismissButton = note.querySelector('[data-rx-note-dismiss]');
var toggleButton = note.querySelector('[data-rx-note-toggle]');
var body = note.querySelector('.rx-medical-note__body');
if (dismissButton) {
dismissButton.addEventListener('click', function () {
note.classList.add('is-hidden');
note.setAttribute('aria-hidden', 'true');
});
}
if (toggleButton && body) {
toggleButton.addEventListener('click', function () {
var isOpen = note.classList.toggle('is-open');
note.setAttribute('data-rx-open', isOpen ? 'true' : 'false');
toggleButton.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
body.hidden = !isOpen;
});
}
});
});
})();
</script>
<?php
endif;
/**
* --------------------------------------------------------------------------
* Render block
* --------------------------------------------------------------------------
*/
do_action( 'rx_theme_medical_note_before', $rx_medical_note_args );
?>
<aside<?php echo $rx_medical_note_attr_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
<?php do_action( 'rx_theme_medical_note_inside_before', $rx_medical_note_args ); ?>
<?php if ( $rx_medical_note_dismissible ) : ?>
<button
type="button"
class="rx-medical-note__dismiss"
data-rx-note-dismiss
aria-label="<?php echo esc_attr__( 'Dismiss medical note', 'rx-theme' ); ?>"
>
<span aria-hidden="true">×</span>
</button>
<?php endif; ?>
<?php if ( $rx_medical_note_collapsible ) : ?>
<button
type="button"
class="rx-medical-note__toggle"
data-rx-note-toggle
aria-expanded="<?php echo esc_attr( $rx_medical_note_default_open ? 'true' : 'false' ); ?>"
aria-controls="<?php echo esc_attr( $rx_medical_note_body_id ); ?>"
aria-label="<?php echo esc_attr__( 'Toggle medical note', 'rx-theme' ); ?>"
>
<span aria-hidden="true">⌄</span>
</button>
<?php endif; ?>
<header class="rx-medical-note__header">
<?php if ( $rx_medical_note_show_icon && $rx_medical_note_icon ) : ?>
<span class="rx-medical-note__icon">
<?php
echo wp_kses(
$rx_medical_note_icon,
array(
'svg' => array(
'viewBox' => true,
'aria-hidden' => true,
'focusable' => true,
'role' => true,
'xmlns' => true,
),
'path' => array(
'd' => true,
'fill' => true,
'fill-rule' => true,
'clip-rule' => true,
),
)
);
?>
</span>
<?php endif; ?>
<div class="rx-medical-note__head-content">
<?php if ( $rx_medical_note_show_badge && $rx_medical_note_badge_text ) : ?>
<span class="rx-medical-note__badge">
<?php echo esc_html( $rx_medical_note_badge_text ); ?>
</span>
<?php endif; ?>
<?php if ( $rx_medical_note_title ) : ?>
<h2 class="rx-medical-note__title" id="<?php echo esc_attr( $rx_medical_note_heading_id ); ?>">
<?php echo esc_html( $rx_medical_note_title ); ?>
</h2>
<?php endif; ?>
<?php if ( $rx_medical_note_subtitle ) : ?>
<p class="rx-medical-note__subtitle">
<?php echo esc_html( $rx_medical_note_subtitle ); ?>
</p>
<?php endif; ?>
</div>
</header>
<div
class="rx-medical-note__body"
id="<?php echo esc_attr( $rx_medical_note_body_id ); ?>"
<?php echo $rx_medical_note_collapsible && ! $rx_medical_note_default_open ? 'hidden' : ''; ?>
>
<?php if ( $rx_medical_note_summary ) : ?>
<div class="rx-medical-note__summary">
<?php echo wp_kses_post( wpautop( $rx_medical_note_summary ) ); ?>
</div>
<?php endif; ?>
<?php if ( $rx_medical_note_content ) : ?>
<div class="rx-medical-note__content">
<?php echo wp_kses_post( wpautop( $rx_medical_note_content ) ); ?>
</div>
<?php endif; ?>
<?php if ( $rx_medical_note_key_points || $rx_medical_note_warning_signs || $rx_medical_note_do_list || $rx_medical_note_dont_list ) : ?>
<div class="rx-medical-note__grid">
<?php if ( $rx_medical_note_key_points ) : ?>
<section class="rx-medical-note__panel">
<h3 class="rx-medical-note__panel-title">
<?php echo esc_html__( 'Key points', 'rx-theme' ); ?>
</h3>
<ul class="rx-medical-note__list">
<?php foreach ( $rx_medical_note_key_points as $point ) : ?>
<li><?php echo esc_html( $point ); ?></li>
<?php endforeach; ?>
</ul>
</section>
<?php endif; ?>
<?php if ( $rx_medical_note_warning_signs ) : ?>
<section class="rx-medical-note__panel">
<h3 class="rx-medical-note__panel-title">
<?php echo esc_html__( 'Warning signs', 'rx-theme' ); ?>
</h3>
<ul class="rx-medical-note__list">
<?php foreach ( $rx_medical_note_warning_signs as $sign ) : ?>
<li><?php echo esc_html( $sign ); ?></li>
<?php endforeach; ?>
</ul>
</section>
<?php endif; ?>
<?php if ( $rx_medical_note_do_list ) : ?>
<section class="rx-medical-note__panel">
<h3 class="rx-medical-note__panel-title">
<?php echo esc_html__( 'What may help', 'rx-theme' ); ?>
</h3>
<ul class="rx-medical-note__list">
<?php foreach ( $rx_medical_note_do_list as $item ) : ?>
<li><?php echo esc_html( $item ); ?></li>
<?php endforeach; ?>
</ul>
</section>
<?php endif; ?>
<?php if ( $rx_medical_note_dont_list ) : ?>
<section class="rx-medical-note__panel">
<h3 class="rx-medical-note__panel-title">
<?php echo esc_html__( 'What to avoid', 'rx-theme' ); ?>
</h3>
<ul class="rx-medical-note__list">
<?php foreach ( $rx_medical_note_dont_list as $item ) : ?>
<li><?php echo esc_html( $item ); ?></li>
<?php endforeach; ?>
</ul>
</section>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ( $rx_medical_note_evidence_level || $rx_medical_note_reviewer || $rx_medical_note_reviewed_date || $rx_medical_note_updated_date ) : ?>
<div class="rx-medical-note__meta" aria-label="<?php echo esc_attr__( 'Medical note information', 'rx-theme' ); ?>">
<?php if ( $rx_medical_note_evidence_level ) : ?>
<span class="rx-medical-note__meta-item">
<strong><?php echo esc_html__( 'Evidence:', 'rx-theme' ); ?></strong>
<?php echo esc_html( $rx_medical_note_evidence_level ); ?>
</span>
<?php endif; ?>
<?php if ( $rx_medical_note_reviewer ) : ?>
<span class="rx-medical-note__meta-item">
<strong><?php echo esc_html__( 'Reviewed by:', 'rx-theme' ); ?></strong>
<?php if ( $rx_medical_note_reviewer_url ) : ?>
<a class="rx-medical-note__link" href="<?php echo esc_url( $rx_medical_note_reviewer_url ); ?>">
<?php echo esc_html( $rx_medical_note_reviewer ); ?>
</a>
<?php else : ?>
<?php echo esc_html( $rx_medical_note_reviewer ); ?>
<?php endif; ?>
</span>
<?php endif; ?>
<?php if ( $rx_medical_note_reviewed_date ) : ?>
<span class="rx-medical-note__meta-item">
<strong><?php echo esc_html__( 'Reviewed:', 'rx-theme' ); ?></strong>
<time datetime="<?php echo esc_attr( $rx_medical_note_reviewed_date ); ?>">
<?php echo esc_html( date_i18n( get_option( 'date_format' ), strtotime( $rx_medical_note_reviewed_date ) ) ); ?>
</time>
</span>
<?php endif; ?>
<?php if ( $rx_medical_note_updated_date ) : ?>
<span class="rx-medical-note__meta-item">
<strong><?php echo esc_html__( 'Updated:', 'rx-theme' ); ?></strong>
<time datetime="<?php echo esc_attr( $rx_medical_note_updated_date ); ?>">
<?php echo esc_html( date_i18n( get_option( 'date_format' ), strtotime( $rx_medical_note_updated_date ) ) ); ?>
</time>
</span>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ( $rx_medical_note_source_url || $rx_medical_note_source_url_2 || ( $rx_medical_note_cta_label && $rx_medical_note_cta_url ) ) : ?>
<div class="rx-medical-note__actions">
<?php if ( $rx_medical_note_source_url ) : ?>
<a class="rx-medical-note__link" href="<?php echo esc_url( $rx_medical_note_source_url ); ?>" rel="nofollow noopener">
<?php echo esc_html( $rx_medical_note_source_label ); ?>
</a>
<?php endif; ?>
<?php if ( $rx_medical_note_source_url_2 ) : ?>
<a class="rx-medical-note__link" href="<?php echo esc_url( $rx_medical_note_source_url_2 ); ?>" rel="nofollow noopener">
<?php echo esc_html( $rx_medical_note_source_label_2 ); ?>
</a>
<?php endif; ?>
<?php if ( $rx_medical_note_cta_label && $rx_medical_note_cta_url ) : ?>
<a
class="rx-medical-note__cta"
href="<?php echo esc_url( $rx_medical_note_cta_url ); ?>"
target="<?php echo esc_attr( $rx_medical_note_cta_target ); ?>"
<?php echo '_blank' === $rx_medical_note_cta_target ? 'rel="noopener noreferrer"' : ''; ?>
>
<?php echo esc_html( $rx_medical_note_cta_label ); ?>
</a>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if ( $rx_medical_note_show_disclaimer && $rx_medical_note_disclaimer ) : ?>
<div class="rx-medical-note__disclaimer">
<?php echo wp_kses_post( wpautop( $rx_medical_note_disclaimer ) ); ?>
</div>
<?php endif; ?>
</div>
<?php if ( $rx_medical_note_print_schema && ! empty( $rx_medical_note_schema['name'] ) ) : ?>
<script type="application/ld+json">
<?php echo wp_json_encode( $rx_medical_note_schema, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</script>
<?php endif; ?>
<?php do_action( 'rx_theme_medical_note_inside_after', $rx_medical_note_args ); ?>
</aside>
<?php
do_action( 'rx_theme_medical_note_after', $rx_medical_note_args );
Example use in any template:
<?php
get_template_part(
'template-parts/blocks/block',
'medical-note',
array(
'type' => 'clinical',
'title' => 'Doctor’s Clinical Note',
'subtitle' => 'Use this section for medically important explanations.',
'content' => 'This note can explain diagnosis, treatment, warning signs, patient safety, or evidence quality in simple English.',
'key_points' => array(
'Always explain medical terms in plain language.',
'Add warning signs when the condition may become serious.',
'Keep treatment advice evidence-based and safe.',
),
'warning_signs' => array(
'Severe pain',
'Breathing difficulty',
'Sudden weakness',
),
'evidence_level' => 'Evidence-informed educational note',
'reviewer' => 'Dr. RX Harun',
'reviewed_date' => '2026-05-16',
'dismissible' => true,
'collapsible' => false,
)
);
?>
You can later move the inline CSS to:
/assets/css/blocks/medical-note.css
and the inline JS to:
/assets/js/blocks/medical-note.js
but for now this single file will
work directly inside your RX Theme.