Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
add comment

2 Answers

up vote 1 down vote accepted

Try this:

<?php
$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
1  
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 –  m0r7if3r Feb 21 '12 at 13:11
add comment

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
add comment

Your Answer

 
discard

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.