Saltar navegación

[Resuelto] Removing the word “Archives” from Content Type archive page title

This support ticket is created hace 4 años, 11 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Zona horaria del colaborador: Asia/Kolkata (GMT+05:30)

Este tema contiene 4 respuestas, tiene 4 mensajes.

Última actualización por liatG hace 4 años, 11 meses.

Asistido por: Minesh.

Autor
Mensajes
#1736499

I have a CPT “Glossary.” The archive page is enlace oculto. I have tried to remove the word “Archives” from the page title several ways, including editing the custom layout and adding custom code to my theme as per ticket https://toolset.com/forums/topic/split-remove-the-word-archive-from-archive-page-titles/. I haven’t been successful. Can you help?
Here is a Loom video detailing the issue. Thanks!
enlace oculto

#1737307

Hello and thank you for contacting the Toolset support.

Would you allow me temporary access to your site backend to check this issue closely. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

#1738399

Minesh
Colaborador

Idiomas: Inglés (English )

Zona horaria: Asia/Kolkata (GMT+05:30)

Jamal is on Vacation. This is Minesh here and I'll take care of this ticket. Hope this is OK.

I've added the following code to "remove-archive-title" code snippet you added to "Custom Code" section offered by Toolset:
=> enlace oculto

add_filter( 'get_the_archive_title','func_remove_archive_word_title',20,3); 
function func_remove_archive_word_title($title) {
  
  if(is_post_type_archive('glossary')){  
    $temp = explode(':',$title);
    if(count($temp) > 1){
      return $temp[1];
    }
   }
}

I can see now "Archives:" word is removed from the archive page: enlace oculto

#1738527

Another way to do this is;

add_filter( 'get_the_archive_title', 'paulg_5_get_the_archive_title' );

function paulg_5_get_the_archive_title( $title ) {
    $prefixes_to_remove = array(
        'Year: ',
        'Archives: ',
        'Company: ',
        'Category: '
        // Add other prefixes you want to remove...
    );
 
    foreach( $prefixes_to_remove as $prefix ) {
        // If title starts with $prefix, remove it and finish
        if( $prefix == substr( $title, 0, strlen( $prefix ) ) )  {
            return substr( $title, strlen( $prefix ) );
        }
    }
 
    // No prefix was matched
    return $title;
}
#1739987

Thank you, I tried the code you gave me but it actually removed the entire page title from all archives except Glossary. I searched again and found an Astra Pro forum post with the fix:

add_filter( 'get_the_archive_title', 'wpsite_archive_title_remove_prefix' );
function wpsite_archive_title_remove_prefix( $title ) {
if ( is_post_type_archive() ) {
$title = post_type_archive_title( '', false );
}
return $title;
}

This worked correctly. Thank you for your help and sorry for the trouble!