1

Currently I'm having some difficulties with below snippet.

As it currently works it shows the_excerpt_rss on a single post and single page. AND it shows the option on is_home().

But what if a page (instead of the 'blog') is the frontpage? If possible I'd like to include the option as well.

I've tried several versions of including is_front_page() but without any luck thus far.

The snippet I'm currently using:

<?php if (is_single() OR is_page()): if (have_posts()): while (have_posts()): the_post(); ?>
    <meta name="description" content="<?php the_excerpt_rss(); ?>">
<?php endwhile; endif; elseif (is_home()): ?>
    <meta name="description" content="<?php $options = get_option('schema_theme_options'); echo $options['metadescription']; ?>">
<?php endif; ?>

3 Answers 3

1

Try if ( 'page' == get_option( 'show_on_front' ) ) {}.

Edit

but I've tried adding and replacing <?php endwhile; endif; elseif (is_home()): ?> with both of your code. Could you perhaps include your snippet with mine?

I'm not sure why you would do that. I was specifically answering this question:

But what if a page (instead of the 'blog') is the frontpage? If possible I'd like to include the option as well.

The answer to that question is what I posted:

`if ( 'page' == get_option( 'show_on_front' )

However, that won't actually solve your problem, if I'm reading your code properly. Reading what you're asking, this should work:

if ( is_single() || is_page() || is_front_page() )

(Note: I used || instead of OR as the Boolean operator.)

To be honest, I'm somewhat surprised that this works on static pages. I didn't know that they generated RSS output.

5
  • if(get_the_ID() == get_option('show_on_front')) {}
    – Pippin
    Jan 18, 2012 at 18:22
  • @chip-bennett and @pippin, I'm probably a newb…, but I've tried adding and replacing <?php endwhile; endif; elseif (is_home()): ?> with both of your code. Could you perhaps include your snippet with mine?
    – user5424
    Jan 18, 2012 at 18:34
  • @Pippin no; please see my comment to your answer. show_on_front returns either page or posts. You're thinking of page_on_front. Jan 18, 2012 at 22:03
  • See updated answer... Jan 18, 2012 at 22:17
  • Much appreciated! I've been using the_excerpt_rss for quite some time now for static pages, according to this guide by Nathan Rice.
    – user5424
    Jan 19, 2012 at 3:08
0
<?php if(get_the_ID() == get_option('show_on_front')) : ?>
     <meta name="description" content="<?php $options = get_option('schema_theme_options'); echo $options['metadescription']; ?>">
<?php elseif(is_single() OR is_page()) : ?>
    <?php if (have_posts()): while (have_posts()): the_post(); ?>
          <meta name="description" content="<?php the_excerpt_rss(); ?>">
    <?php endwhile; endif; ?>
<?php endif; ?>

How's that?

3
  • I think you need get_the_ID() == get_option( 'page_on_front' ). The page_on_front option returns the ID of the static page set to display on the front page. The page_for_posts option returns the ID of the static page set to display the blog posts index. The show_on_front option returns either page or posts, depending on what the front page is set to display. Jan 18, 2012 at 22:02
  • Ah, yes, you're right.
    – Pippin
    Jan 19, 2012 at 0:53
  • Using page_on_front does indeed do the trick. Thanks a lot!
    – user5424
    Jan 19, 2012 at 3:10
0

Hopefully I would be within the rules when adding this reply (I've been thinking about editing my original question instead)

First of all, @chip-bennett is right. I haven't been 100% clear when asking my question. I wanted to use the_excerpt_rss for single posts and pages, and if the home page would show a static page or the posts page, I'd like to use the option.

Therefore, for future reference, this is the code I'm currently using:

<?php if (is_home() OR is_front_page()): ?>
    <meta name="description" content="<?php $options = get_option('schema_theme_options'); echo $options['metadescription']; ?>">
<?php elseif (is_single() OR is_page()): if (have_posts()): while (have_posts()): the_post(); ?>
    <meta name="description" content="<?php the_excerpt_rss(); ?>">
<?php endwhile; endif; endif ?>

Your Answer

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