Wordpress 小部件之前和之后的空段落标签

问题描述 投票:0回答:1
php wordpress widget shortcode
1个回答
0
投票

我发现

标签是由默认的古腾堡脆饼小部件添加的,通过创建自定义小部件并使用它添加短代码来解决这个问题

<?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' );
© www.soinside.com 2019 - 2024. All rights reserved.