Archived topic
Best way to change archive titles
7 replies · Started by Fernando on January 9, 2019
Hello!
What is the best way to change the categories title, searchs title, not found title and in general all the archive pages titles with GP Premium?
I am thinking in several options, like using a WP or GP filter (generate_archive_title?), or use a header element and hide the .page-header class with CSS... But I'd like to know if there is a better option.
Examples: I don't what to show Category: name, or Archive: date, Author: name, etc. I want to custom this texts, also in custom posts types like Archive: products... making this Products catalogue, for example.
Suggestion: perhaps you should include it in Elements > Layouts > Disable archive title (also applies to categoriy, search or not found pages).
Thanks!
Hi there,
I believe this is what you are looking for:
https://developer.wordpress.org/reference/functions/get_the_archive_title/
You can see lots of examples if you search get_the_archive_title in our forum.
Let me know if this helps :)
Hello Leo! I explain...
I have a custom post type called products and want archive pages, but not the default ugly title: Archives: products.
I was trying to custom this title with a header element, like in blog entries, but it is not possible to hide the default header.page-header without additional css. So a good new option in layout elements would be to hide/disabled this titles (the header.page-header container, tell this to Tom :-)).
Note that the archive <title> tag is no problem, as can be changed with Yoast Seo.
As a result, I am seeing that the best way to do this is with the filter hook get_the_archive_title, isn't it?
As this function:
add_filter( 'get_the_archive_title' ,'rvfa_product_archive_title' );
function rvfa_product_archive_title($title) {
if ( is_post_type_archive('rvfa_product') ) $title = 'Catálogo de productos';
return $title;
} // :/function
And this result:
So a good new option in layout elements would be to hide/disabled this titles (the header.page-header container, tell this to Tom :-)).
Might be a good idea for the Layout Element. It's easy to remove with a line of PHP for now though, if you need. If you use {{post_title}} in a Hero Element, it will remove the archive title by default.
get_the_archive_title is definitely the way to go for now. It offers the most flexibility. Looks like it's working nicely for you :)
Hello Tom,
That was! When insert the {{post_title}} tag in a header element, and apply to the archive page, the default archive title dissapears!
I was testing other thing: to disable the content title in a layout element, but that doesn't work in archive pages.
Note that I am new with this plugin. I am a user of the GP free theme since the first versions, but not of GP Premium. Possibilities are (almost) endless, congratulations!
That's right, the content title option won't work in archives. That's an interesting idea though - I'll look into it :)
Thanks!
Hi,
I've tried this but somehow it isn't working...
Here is my function
// ARCHIVE TITLE FILTER
function sy_archive_title( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false ) . ' Government Schemes';
}
return $title;
}
add_filter( 'get_the_archive_title', 'sy_archive_title');
Hi there,
Try giving it a later priority:
function sy_archive_title( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false ) . ' Government Schemes';
}
return $title;
}
add_filter( 'get_the_archive_title', 'sy_archive_title', 50);