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?

link|improve this question

feedback

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.

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

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).

link|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 at 12:36
feedback

Your Answer

 
or
required, but never shown

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