How to remove the category or archive prefix in WordPress

What’s discussed here?

By default, WordPress adds a prefix to archive pages. You can use the add_filter function to modify the output when the archive page loads.

You can either add the code in your own plugin or add it to your functions.php file within your theme. (It’s strongly advised to add it to a child theme).

add_filter('get_the_archive_title', function ($title) {
    if (is_category()) {
        $title = single_cat_title('', false);
    } elseif (is_tag()) {
        $title = single_tag_title('', false);
    } elseif (is_author()) {
        $title = '<span class="vcard">' . get_the_author() . '</span>';
    } elseif (is_tax()) { //for custom post types
        $title = sprintf(__('%1$s'), single_term_title('', false));
    } elseif (is_post_type_archive()) {
        $title = post_type_archive_title('', false);
    }
    return $title;
});

The above code was taken from StackExchange

For WPdocs.io, I didnt want to remove the title, but instead amend. So the function used on this site is:

/**
 * Amend Prefix text of archive titles
 */

add_filter('get_the_archive_title', function ($title) {
    if (is_category()) {
        $title = single_cat_title('WPdocs ', false);
    } elseif (is_tag()) {
        $title = single_tag_title('Articles mentioning ', false);
    } elseif (is_author()) {
        $title = '<span class="vcard">' . get_the_author() . '</span>';
    } elseif (is_tax()) { //for custom post types
        $title = sprintf(__('%1$s'), single_term_title('', false));
    } elseif (is_post_type_archive()) {
        $title = post_type_archive_title('', false);
    }
    return $title;
});

Notice that ‘WPdocs’ was added to single_cat_title and ‘Articles mentioning’ was added to single_tag_title.

Read more about the subject above