In archive.php – Replace this :
<?php
the_archive_title( ‘<h1 class=”page-title”>’, ‘</h1>’ );
the_archive_description( ‘<div class=”archive-description”>’, ‘</div>’ );
?>
with : <?php
// Get the archive title without the prefix
$archive_title = get_the_archive_title();
$archive_title = preg_replace( ‘/^.*?:\s*/’, ”, $archive_title );
// Remove any HTML tags from the archive title, including <span>
$archive_title_clean = strip_tags( $archive_title );
// Display the modified archive title
echo ‘<h1 class=”page-title”>’ . esc_html( $archive_title_clean ) . ‘</h1>’;
// Display the archive description
the_archive_description( ‘<div class=”archive-description”>’, ‘</div>’ );
?>
Here’s an updated version of your code that removes any prefix:
php
<?php $archive_title = get_the_archive_title(); $prefixes_to_remove = array('Category: ', 'Tag: '); // Add more prefixes if needed // Remove prefixes $trimmed_title = str_replace($prefixes_to_remove, '', $archive_title); echo '<h1 class="page-title">' . $trimmed_title . '</h1>'; the_archive_description( '<div class="archive-description">', '</div>' ); ?>
In this version, you can easily add more prefixes to the $prefixes_to_remove
array if needed. The str_replace
function will then remove any of the specified prefixes from the archive title.
Replace your existing code with this modification in your archives.php
file.