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

I might be doing this all wrong. I have a custom field called "enable_adsense" and the value can be either "yes" or "no"

What I'm trying to do is display something if the value is "yes" and something else if it's "no".

Here's what I have so far:

global $post;
$enable_adsense = get_post_meta($post->ID, 'enable_adsense', true);
if ($enable_adsense == 'yes') { ?>

    Adsense code goes here

<?php } else { ?>
share|improve this question
If your meta value is what you say it is that should work. What is the question? – s_ha_dum Oct 17 '13 at 23:36
That's the thing it's not working. – Chozen Oct 17 '13 at 23:40
Then your post meta is not what you say it is. Do some debugging-- say, var_dump($disable_adsense); – s_ha_dum Oct 17 '13 at 23:42
This is how it appears: Screeenshot, does this have to be in the loop? Because it's in the sidebar and only returning what comes after the "else" – Chozen Oct 17 '13 at 23:49
For $post to work correctly, yes, it has to be in a Loop. I didn't ask for a screenshot of the backend. I asked for a var_dump. – s_ha_dum Oct 17 '13 at 23:58

Your Answer


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

Browse other questions tagged or ask your own question.