نحوه ساخت شورتکد سفارشی در وردپرس (WordPress Shortcode)
با تابع `add_shortcode` و استفاده صحیح از خروجی رشتهای (return به جای echo) شورتکد سفارشی بسازید.
<?php
/**
* ساخت شورتکد باکس پیام و هشدار سفارشی
* نحوه استفاده در متن: [bisco_alert type="success"]متن پیام شما[/bisco_alert]
*/
function bisco_alert_box_shortcode( $atts, $content = null ) {
$atts = shortcode_atts( array(
'type' => 'info', // پیشفرض: info, warning, success, error
), $atts, 'bisco_alert' );
$type_class = sanitize_html_class( $atts['type'] );
$output = '<div class="bisco-alert-box alert-' . esc_attr( $type_class ) . '">';
$output .= do_shortcode( $content );
$output .= '</div>';
return $output;
}
add_shortcode( 'bisco_alert', 'bisco_alert_box_shortcode' );