php function in add_shortcode
-
I would like to make a shortcode to display a trackinglist of an album. This data is stored in meta key “_product_attributes”. The PHP snippet works when I test it in my functions.php, but I don’t find the right way to make it work as a shortcode, to be used in Gutenberg blocks, shortcode blocks…. Anybody knows how I can make it as a registered add_shortcode()? Here under is my PHP snippet, that works:
add_action( 'woocommerce_single_product_summary', 'display_tracklist', 20 ); function display_tracklist(){ global $product; // Get the tracklist field value $custom_field = get_post_meta( $product->get_id(), '_product_attributes', false ); // Display if( ! empty($custom_field) ){ $tracks = $custom_field[0]['Tracklisting']['value']; echo '<span class="track">' . nl2br($tracks) . '</span><br>'; } }
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘php function in add_shortcode’ is closed to new replies.