I want to call custom field in single.php template to complete a short code and thus show a menu.

I places the below code but it is not working

<?php echo do_shortcode("[custommenu menu=<?php echo get_post_meta($post->ID, ‘tabmenu’, true); ?>]?>")

2 Answers 2


I believe you forgot to add quotes around the menu parameter.

<?php $post_meta_value = get_post_meta($post->ID, 'tabmenu', true);
echo do_shortcode('[custommenu menu="'.$post_meta_value.'"]'); ?>
  • This works but he issue is that. I have two menus say MENU0 MENU1. But this code shows Menu0 on every post either I have MENU0 or MENU1 in tabmenu custom field
    – Rob Morta
    Oct 31, 2012 at 4:08

Try using this code. Hope this will work.

$post_meta_value = get_post_meta($post->ID, 'tabmenu', true);
echo do_shortcode('[custommenu menu='.$post_meta_value.']');
  • its not working returning the same code on page
    – Rob Morta
    Oct 30, 2012 at 8:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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