How to Display Category Description on Category Page
-
Hi there,
I want to display category description on category archive below the title, How can i do this? I am using a child theme.
// Function to display category description on category archive page
function display_category_description() {
if (is_category()) { // Check if it's a category archive page
$category = get_queried_object(); // Get the current category object
$category_description = category_description($category->term_id); // Get the category description
if ($category_description) {
echo '<div class="category-description">';
echo '<h2>About ' . esc_html($category->name) . '</h2>';
echo wp_kses_post($category_description); // Display the description safely
echo '</div>';
}
}
}
// Hook to display category description before the category posts
add_action('loop_start', 'display_category_description');Placed this in my function.php file but it displays the description above the header, I tried some tweaking but result is same.
How can i do this?
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- You must be logged in to reply to this topic.