I'm working on a template-part
called heading
which displays the page heading and an optional subtitle underneath. I have it working on pages, but on archive pages like our blog or product category pages, it returns the first matching post title.
Here's the code:
$id = get_the_ID();
$heading = get_the_title();
$sub_heading = get_field('sub_heading', $id);
if (is_home() || is_category()) {
$heading = get_the_title(12);
$sub_heading = 'Learn, Modify, Create.';
} else if (is_404()) {
$heading = '404';
$sub_heading = "Well, this is awkward.";
} else if (is_shop()) {
$heading = 'SHOP';
$sub_heading = "Explore our complete product offering here";
} else if (is_product_category()) {
$sub_heading = category_description();
}
?>
<div class="page-heading-section-wrapper">
<div class="page-heading-section">
<h1 class="main-heading"><?php echo $heading; ?> </h1>
<?php if ($sub_heading) {
echo '<h2 class="sub-heading">' . $sub_heading . '</h2>';
}; ?>
</div>
</div>
Example:
If I had a product category of "Balloons" and my products within it were "Birthday", "Holiday" etc, the title on the archive page would be "Birthday". The category description seems to work fine.
What am I doing wrong?