I try to change title on Archive page because i use it to list custom article type. In fact, i want to remove "Archive " text at the start of page title.
I use wordpress 5.8 and a custom theme from twenty twenty.
In my header.php file, there is that :
<?php wp_head(); ?>
But when i write the code below into my functions.php
, nothing happens.
remove_action('wp_head', '_wp_render_title_tag');
I have also try to use filter but i don't use it properly because nothing happens too.
How can i do that ?
Thanks !
CodePudding user response:
This one should do the trick :
function change_archive_page_title( $title ) {
if ( is_category() ) {
$title = single_cat_title( '', false );
}
return $title;
}
add_filter( 'get_the_archive_title', 'change_archive_page_title' );
Add it to your child theme -> functions.php Edit: It replace the page title with empty string.
CodePudding user response:
To change the Archive Title, there are a few ways. One is probably using an SEO plugin? But to do it programmatically, you can use the filter get_the_archive_title
Change your_taxonomy
to the name of the taxonomy you want to modify what is displayed.
add_filter( 'get_the_archive_title', 'custom_archive_title', 10, 3 );
/**
* Change the archive title for a custom taxonomy
*
* @param string $title - The full archive Title
* @param string $original_title - The name of the archive without prefix.
* @param string $prefix - Prefix if set - otherwise "Archive"
* @return mixed
*/
function custom_archive_title( $title, $original_title, $prefix ) {
// Get the queried object - which would be the WP_Term.
$queried_object = get_queried_object();
// Check if it's your custom taxonomy
if ( 'your_taxonomy' === $queried_object->taxonomy ) {
// Remove the prefix.
$title = $original_title;
}
return $title;
}