Displaying Category Headings on all Category Archive Pages in Genesis

In a Genesis WordPress theme you can add in a headline to display for a Category archive page, but this headline only appears on the initial category archive page, so  if pagination exists for subsequent archive pages then other pages do not have the title rendered.

genesis-category-heading

 

To get around this issue if you have pagination on your category archives the problem is better solved with a function in your themes function.php file

function themeprefix_category_header() {
if ( is_category() )  {
		echo '<h1 class="archive-title">';
		echo single_cat_title();
		echo '</h1>';
	}
}
add_action( 'genesis_before_loop' , 'themeprefix_category_header' );

The function above will only run if the content is a category page and then render the actual category title in h1 tags with a class of archive-title set to it. It will display on all the same category archive pages.

If you wanted something other than the category title you drop the single_cat_title for something else…

function themeprefix_category_header() {
if ( is_category() )  {
	echo '<h1 class="archive-title">Your Heading Here</h1>';
	}
}
add_action( 'genesis_before_loop' , 'themeprefix_category_header' );

 

The action will place the archive heading just outside of the loop.

genesis-category-before-loop

This can also be applied to tags

function themeprefix_tag_header() {
if ( is_tag() )  {
		echo '<h1 class="archive-title">';
		echo single_tag_title();
		echo '</h1>';
	}
}
add_action( 'genesis_before_loop' , 'themeprefix_tag_header' );

A lot of sites won’t have a need for this but when those archives build over time or a small amount of posts per archive page is applied its a handy setting to add.

Gist.

3 Comments

  1. Philip Murray on June 23, 2016 at 9:37 am

    Thanks for this – can you show how to add the ARCHIVE DESCRIPTION in also please?

    thanks

    Phil

  2. Manish on June 29, 2015 at 11:17 am

    Hello,

    I have used the same code in my theme’s functions.php, but I am surprised it is not visible when I am not logged in.

    Please help me out. 🙁

  3. Aaron on May 11, 2015 at 7:30 pm

    This was exactly what I needed. I’m always surprised that themes constantly say that they are SEO Friendly out of the box, when the truth is they rarely are. Especially Genesis.

Leave a Comment





%d bloggers like this: