• I’m trying to replace the site header and tagline with category name and description, based on post category.

    The code, below, works fine on category pages. It replaces both the title and the tagline.

    On posts within a category though, the category name replaces the site headline, but the category description doesn’t replace the tag line.

    Here is a category page (works right): http://miketurco.com/consulting-services/

    Here’s a post within a category. The title is replaced but the tagline is not:

    http://miketurco.com/vendor-referrals-and-management/

    This is the code:

    <?php if (is_category() || is_single() ){ ?>
                        <span class="home-link">
                        <h1 class="site-title"><?php the_category(' '); ?></h1>
                        <h2 class="site-description"><?php echo category_description(); ?></h2>
                        </span>
                    <?php } else { ?>
                        <a class="home-link" href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home">
                        <h1 class="site-title"><?php bloginfo( 'name' ); ?></h1>
                        <h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
                        </a>
                    <?php } ?>

    Thank You!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter miketurco

    (@miketurco)

    Title should have been “what’s the difference between the_category and category_description()?”

    Moderator bcworkz

    (@bcworkz)

    category_description() only works without parameters for category queries, not post queries (even posts within a category). If you get the category ID from the post and supply it as a parameter it will work.

    the_category() without parameters works because it works off the current post so works in both cases.

    Thread Starter miketurco

    (@miketurco)

    I tried doing that before. I was probably on the right track but couldn’t get it going — I’m in the middle of the learning curve. I’ll try again. Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Diff between bloginfo( 'name' ) and bloginfo( 'description' )?’ is closed to new replies.