Skip to main content
Login Join
Snippet · PHP

Remove Archive Title Prefixes (WordPress & WooCommerce)

Shared by Mohamed Amine Abla · June 4, 2026 · @get_the_archive_title

6 views
2 upvotes
Back to Snippets

This WordPress snippet hooks into the get_the_archive_title filter to clean up the default page titles displayed on archive pages.

function custom_titles($title) {
    if(class_exists( 'WooCommerce' )) {
        $is_woo_page = is_shop() || is_product_category() || is_product_tag();
    } else {
        $is_woo_page = false;
    }

    if ($is_woo_page || is_category() || is_tag() || is_date() || is_author()) {
        $title = str_replace(':', '', ltrim($title, strtok($title, ':')));
        $title = str_replace('</span>', '', $title);
        $title = str_replace('<span>', '', $title);
    }
    return $title;
}

add_filter('get_the_archive_title', 'custom_titles');