Display category title and description on Category Page

I figured out how to display the category title on my category pages by using the info in this post: https://theme.co/apex/forum/t/how-do-i-display-the-title-on-blog-post-and-category-pages/40568/2

However, none of the other posts I found will also show the category description. Can you tell me what to add to the code to also display the category description? This is one of my category pages https://update.breakup.expert/blog/category/breakup-advice/

This is what I posted in my child theme’s functions.php:

// Add post Category Titles
// =============================================================================
function add_category_titles(){  ?>
  <?php if ( is_category() || x_is_portfolio_category() ) : ?>

  <?php
  
  $meta     = x_get_taxonomy_meta();
    $subtitle = ( $meta['archive-subtitle'] != '' ) ? $meta['archive-subtitle'] : __( 'REALISTIC ADVICE FOR ', __x__ ) . '<strong>' . single_cat_title( '', false ) . '</strong>';

  ?>

  <header class="x-header-landmark x-container max width">
       <h3 class="h-landmark" style="font-family:Montserrat;font-weight:200px;letter-spacing:.03EM;line-height:100%"><span><?php echo $subtitle ?></span></h3>
  </header>

  <?php endif;
}
add_action('x_after_view_global__slider-below', 'add_category_titles');

// =============================================================================

Hi,

Please change the code you have added with this

  // Add post Category Titles
// =============================================================================
function add_category_titles(){  ?>
  <?php if ( is_category() || x_is_portfolio_category() ) : ?>

  <?php
  
   $meta     = x_get_taxonomy_meta();
 
   $title    = ( $meta['archive-title']    != '' ) ? $meta['archive-title']    : __( 'Category Archive', '__x__' );
   $subtitle = ( $meta['archive-subtitle'] != '' ) ? $meta['archive-subtitle'] : __( "Below you'll find a list of all posts that have been categorized as ", '__x__' ) . '<strong>&ldquo;' . single_cat_title( '', false ) . '&rdquo;</strong>';

  ?>

    <header class="x-header-landmark x-container max width">
    <h1 class="h-landmark"><span><?php echo $title ?></span></h1>
    <p class="p-landmark-sub"><span><?php echo $subtitle ?></span></p>
     <p class="p-landmark-desc"><span><?php echo category_description(); ?></span></p>
  </header>
  <?php endif;
}
add_action('x_after_view_global__slider-below', 'add_category_titles');

// =============================================================================

You can then add your category title, subtitle and description in Edit Category Page

Hope that helps

Thank you so much! That worked!

You’re welcome.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.