There is a way to change the WordPress archive title without changing the theme's original files. The main reason I think WordPress is fantastic is flexibility. Most WordPress themes like Codeless Themes use the function “get_the_archive_title()” to show the category titles and other archive pages.
Sometimes you want to change the default “Category:” string to “Albums:”. There are two ways :
- Hardcode changes in the original theme files
- Using WordPress filter and child theme
The first method is problematic because when you will try to update the theme the change can be lost. The best way is to use Child Theme and in the functions.php file of the Child Theme, you can add the add_filter function. Check out how to configure a child theme: How to Install a Child Theme.
add_filter( 'get_the_archive_title', function ( $title ) { if( is_category() ) { $title = 'Albums'; } return $title; });
In the example above you see that we have overwritten the get_the_archive_title. If that case we have to change the title only for the category archive type.
If you want to change the title of the search page you can use the conditional into is_search().
The add_filter can be used for any other WordPress default functions.
Ludjon, who co-founded Codeless, possesses a deep passion for technology and the web. With over a decade of experience in constructing websites and developing widely-used WordPress themes, Ludjon has established himself as an accomplished expert in the field.
Comments