我正在为我的wordpress网站使用Shortcode。该代码工作正常。但不适用于p标签。例如
[box type=”shadow”]<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>[/box]
这是我的代码
function boxShow($atts, $content = null ){
//default values
$option = shortcode_atts( array(
'type' => '',
), $atts );
ob_start();
$class = $option[ 'type' ] ? str_replace( '"', '', $option[ 'type' ] ) : 'normal';
//HTML goes here
?>
<div class="box <?php echo $class; ?>"><?php echo $content; ?></div>
<?php
$output = ob_get_clean();
return $output;
}
add_shortcode( 'box', 'boxShow' );
答案 0 :(得分:0)
您应按以下方式使用简码:
[box type=shadow]<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>[/box]
并将代码更改为
function boxShow($atts, $content = null ){
$option = shortcode_atts( array(
'type' => '',
), $atts );
$class = $option[ 'type' ] ? str_replace( '"', '', $option[ 'type' ] ) : 'normal';
$output = '<div class="box '.$class.'">'.$content.'</div>';
return $output;
}
add_shortcode( 'box', 'boxShow' );