この記事では関数「shortcode_atts」を使用して、ショートコードに属性を追加します。
shortcode_attsの解説
ショートコードの属性に数字を入力して、5を掛けた数字を出力します。
function price_test( $atts ) {
$atts = shortcode_atts(array('price' => '100',), $atts, 'total' );
return $atts['price'] * 5;
}
add_shortcode( 'total', 'price_test' );ショートコードはtotal price=150を[]で括ります。
属性を入力しない場合は、デフォルトの100に5を掛けた数値が出力されます。

