我发现
标签是由默认的古腾堡脆饼小部件添加的,通过创建自定义小部件并使用它添加短代码来解决这个问题
<?php
// Register shortcode widget
class Shortcode_Widget extends WP_Widget {
public function __construct() {
parent::__construct(
'shortcode_widget',
__( 'Shortcode Widget', 'text_domain' ),
array(
'description' => __( 'A widget that displays a shortcode.', 'text_domain' ),
)
);
}
public function widget( $args, $instance ) {
$shortcode = ! empty( $instance['shortcode'] ) ? $instance['shortcode'] : '';
echo do_shortcode( $shortcode );
}
public function form( $instance ) {
$shortcode = ! empty( $instance['shortcode'] ) ? $instance['shortcode'] : '';
?>
<p>
<label for="<?php echo $this->get_field_id( 'shortcode' ); ?>"><?php _e( 'Shortcode:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'shortcode' ); ?>" name="<?php echo $this->get_field_name( 'shortcode' ); ?>" type="text" value="<?php echo esc_attr( $shortcode ); ?>" />
</p>
<?php
}
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['shortcode'] = ! empty( $new_instance['shortcode'] ) ? $new_instance['shortcode'] : '';
return $instance;
}
}
function register_shortcode_widget() {
register_widget( 'Shortcode_Widget' );
}
add_action( 'widgets_init', 'register_shortcode_widget' );