Support » Plugin: Post Snippets » Function as snippet?

  • I have this shortcode in my functions.php file

    add_shortcode( 'buy_status', 'wpse249289_buy_status' );
    function wpse249289_buy_status( $atts ) {
        $output = '';
        if ( ! get_post_meta( get_the_ID(), 'buy_status', true ) ) {
            // Post meta value for key buy_status is false
            $output .= '<h5 style="text-align: center;display: block;">';
            $output .= 'Sorry, this piece is sold.';
            $output .= '</h5>';
        } else {
            // Post meta value for key buy_status is not false
            $output .= '<h5 style="text-align: center;display: none;"></h5>'; // Not sure why you'd want to output anything
        return $output;

    I would like to put it in Post Snippets and call it from there. I’ve tinkered with doing that but can’t get it to work.

    How would I put the code in Post Snippets? I assume the shortcode and php checkboxes would be checked?


  • The topic ‘Function as snippet?’ is closed to new replies.