How I can add placeholder in shortcode

add_shortcode( 'show-the-views', function( ) {);$count = get_post_meta( get_the_ID(), 'views', true

  add_shortcode( 'show-the-views', function( ) {
    );
    $count = get_post_meta( get_the_ID(), 'views', true );
    return $count . ' views';
});

This code is working but I have to add a placeholder in the shortcode for example [doc_wp_live_search placeholder="Have a question?"]. Currently, it is showing views. But I want to give an option for the user.

  add_shortcode( 'show-the-views', function( ) {
    );
    $count = get_post_meta( get_the_ID(), 'views', true );
    return $count . ' views';
});

This code is working but I have to add a placeholder in the shortcode for example [doc_wp_live_search placeholder="Have a question?"]. Currently, it is showing views. But I want to give an option for the user.

Share Improve this question edited May 27, 2019 at 11:35 fuxia 107k39 gold badges255 silver badges459 bronze badges asked May 27, 2019 at 10:34 AnkushAnkush 33 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0
function show_the_views_func( $atts ){
    $atts = shortcode_atts(
        array(
            'placeholder' => '',
        ), $atts 
    );

    $count = get_post_meta( get_the_ID(), 'views', true );

    return $count . $atts['placeholder'] . ' views';
}
add_shortcode( 'show-the-views', 'show_the_views_func' );
echo do_shortcode( '[show-the-views placeholder="test"]' );

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745460402a4628682.html

相关推荐

  • How I can add placeholder in shortcode

    add_shortcode( 'show-the-views', function( ) {);$count = get_post_meta( get_the_ID(), 'views', true

    9小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信