WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to get page's metabox value within shortcode that is executed on that page?


  • I have a sidebar metabox for every page.
  • I have some kind of custom gallery shortcode.

My gallery shortcode outputs 600x200 images (I'm using timthumb here).

BUT I want it to display 900x300 if there's no sidebar.

Normally I'd use:

$sidebar = get_post_meta($post->ID, 'metabox_sidebar', true);
   if($sidebar == "true") { do something }
   else { do something else }

But get_post_meta returns nothing within the shortcode body.

share|improve this question
up vote 1 down vote accepted

$post is outside the scope of your shortcode function, you have to globalize it first:

global $post;
$sidebar = get_post_meta($post->ID, 'metabox_sidebar', true);
share|improve this answer
Oh, my, God :) It's always like this, I'm working on complex things and everything works better than expected then something like this happens and I'm stuck. Thanks a lot, sorry for another super-lame question. – Wordpressor Nov 11 '11 at 1:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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