0

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?

1

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.

| improve this answer | |
  • Like a charm :) Much appreciated! – user5424 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 – mor7ifer Feb 21 '12 at 13:11
0

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

| 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 – user5424 Feb 21 '12 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy