このショートコードを複数回使用すると、すべてのショートコードがaddpadクラスとインラインスタイルの出力を取得します。どのようにすれば、属性を持つショートコードだけがコードを出力するのですか?Wordpress PHPショートコードページのすべてのショートコードを引き出す場合
function block_one_third($atts, $content = null) {
extract(shortcode_atts(array(
'bg' => '',
'text' => '',
), $atts));
if (isset($bg) || isset($text)){ $style = ' style="background-color:'. $bg .';color:'. $text .'"';}
if (isset($bg) || isset($text)) { $padit = ' addpad'; }
return '<div class="one_third'. $padit .'"'. $style .'>' . do_shortcode($content) . '</div>';
}
add_shortcode('one_third', 'block_one_third');
[one_third]
Block 1 - Should have NO additional class or inline style
[/one_third]
[one_third bg="red"]
Block 2 WITH additional html output
[/one_third]
[one_third_last]
Block 3 - Should have NO additional class or inline style
[/one_third_last]
'one_third_last'のショートコードはありますか? – Chris
はい、申し訳ありませんが、このコメントは表示されませんでした。私は最後のものをone_thirdに変更しただけで、同じ問題を抱えていました。 –