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.
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.
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.
Thanks for this – can you show how to add the ARCHIVE DESCRIPTION in also please?
thanks
Phil
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. :-(
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.