0
  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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.