PHP Code SnippetAfter installing a child theme, navigate to Appearance > Theme Editor > functions.php and paste at the bottom of the input.
function custom_post_meta_shortcode($atts) { // Shortcode attributes - includes defaults $atts = shortcode_atts( array( 'post_id' => 0, // default to current post 'meta_key' => '', // no default key 'single' => true, // whether to return a single value ), $atts, 'post_meta' );
// Retrieve post meta $meta_value = get_post_meta($atts['post_id'], $atts['meta_key'], $atts['single']);
// Return the meta value if it exists, otherwise return an empty string return $meta_value ? $meta_value : ''; }
// Register the shortcode with WordPress add_shortcode('post_meta', 'custom_post_meta_shortcode');