dongliao2241 2015-09-30 15:57
浏览 38
已采纳

在我的select元素中添加一个类

I simply want to add class of "btn" to my select element. So the select element will look like

<select class="btn">

Add the class in this code:

<form id="category-select" class="category-select" action="<?php echo esc_url( home_url( '/' ) ); ?>" method="get">

        <?php
        $args = array(
            'show_option_none' => __( 'Select category' ),
            'show_count'       => 1,
            'orderby'          => 'name',
            'echo'             => 0,
        );
        ?>

        <?php $select  = wp_dropdown_categories( $args ); ?>
        <?php $replace = "<select$1 onchange='return this.form.submit()'>"; ?>
        <?php $select  = preg_replace( '#<select([^>]*)>#', $replace, $select ); ?>

        <?php echo $select; ?>

        <noscript>
            <input type="submit" value="View" />
        </noscript>

    </form>
  • 写回答

2条回答 默认 最新

  • duankuaiwang2706 2015-09-30 16:04
    关注

    The documentation shows an option of 'class' in the args you provide

    $args = array(
            'show_option_none' => __( 'Select category' ),
            'show_count'       => 1,
            'orderby'          => 'name',
            'echo'             => 0,
            'class'            => 'btn'
        );
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?