Thông tin liên hệ

Quốc Trần - Quận Gò Vấp, TP. Hồ Chí Minh

Liên hệ hỗ trợ 0906891294 Zalo
Mạng xã hội
Remove “Category:”, “Tag:”, “Author:” from the_archive_title
Avatar
Cá Mập
  • 10/01/2024
  • Blog

This gives me titles like “Category: Russia”, “Tag: America”, “Author: John”.

I would like to remove the “Category:”, “Tag:” and “Author:” part and just display the category, tag and author names.

Does anyone know how to accomplish this?

Here is the code, you can add it to function.php
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;
});

 

 

Đánh giá bài viết
Avatar
Cá Mập

Cá Mập code lập trình wordpress, chia sẽ kiến thức, thủ thuật về web wordpress. Liên hệ làm việc 0906 891 294 ( Phone, Zalo )