admin管理员组

文章数量:1426041

  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"]' );

本文标签: How I can add placeholder in shortcode