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

First, I have to admit I'm not entirely sure on how to explain this best.

Currently I have this in my header.php:

<?php if ( is_home() OR is_front_page() ): ?>
  <meta name="description" content="<?php $options = get_option( 'schema_theme_options' ); echo $options['metadescription']; ?>">
<?php endif; ?>

Would it be possible to hide the remaining

<meta name="description" content="">

if no option availabe?

share|improve this question
up vote 1 down vote accepted

Try this:

$options = get_option( 'schema_theme_options' );
$meta_desc = $options['metadescription'];
<?php if( ( is_home() || is_front_page() ) && '' !== $meta_desc ) : ?>
    <meta name="description" content="<?php echo $meta_desc; ?>">
<?php endif; ?>

It's a bit neater and a bit more foolproof than the other proposed solution.

share|improve this answer
Like a charm :) Much appreciated! – Cor van Noorloos Feb 21 '12 at 12:56
What if $meta_desc is "0"? Better use !== instead of !=. – Geert Feb 21 '12 at 13:03
Good catch, updated...though 0 would be a pretty crappy meta description lol – mor7ifer Feb 21 '12 at 13:11

Try this:

<?php if ( (is_home() || is_front_page()) && ($options = get_option( 'schema_theme_options')) ): ?>
  <meta name="description" content="<?php echo $options['metadescription']; ?>">
<?php endif; ?>

The get_option() function will return false if the requested option does not exist in the database (or if the options's value is false, obviously).

share|improve this answer
Hello @tbuteler, This is indeed where I get stuck, as it still leaves the empty <meta name="description" content="">. Could it be caused by something else in my theme options file? gist.github.com/1876286 – Cor van Noorloos Feb 21 '12 at 12:36

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.