How do I insert a php variable into a Wordpress shortcode?
What about this approach?
function my_shortcode_function( $attributes ) { global $post; // manage attributes $a = shortcode_atts( array( 'foo' => 'something', 'bar' => 'something else', ), $attributes ); // do sth with the custom field $asin = get_post_meta( $post->ID, 'asin', true);}add_shortcode('my_shortcode', 'my_shortcode_function');
So don 't try to get the custom value in the template. Just deal with it in the shortcode function. Through the global declared $post variable it should work. Yes, global ist not very clean. But it 's wordpress ...