Support » Theme: Twenty Twenty-One » How to hide the word Category:

  • Resolved bensontel2

    (@bensontel2)


    I want to set the word Category: to display none but keep the title. How to? Thanks.

    The page I need help with: [log in to see the link]

Viewing 12 replies - 1 through 12 (of 12 total)
  • If you want to remove the archive pages title prefix then please add the below filter in your child theme functions.php at the bottom then it works fine.

    add_filter( 'get_the_archive_title_prefix', '__return_empty_string' );

    Thread Starter bensontel2

    (@bensontel2)

    Thank you, Mukesh and Michael. I used Mukesh’s add-filter and it worked!

    • This reply was modified 3 months, 4 weeks ago by bensontel2.

    Hi @bensontel2,

    The problem with @mukesh27 solution is that, although simple, it removes ALL prefixes including Month, Author, Year, Day, Galleries, etc, etc, etc

    With Options for Twenty Twenty-One plugin, we use this function to make sure that only Category and Tag prefixes are removed 🙂

    function custom_remove_archive_title_prefix($prefix) {
    if ($prefix === 'Category:' || $prefix === 'Tag:') {
    $prefix = '';
    }
    return $prefix;
    }
    add_filter('get_the_archive_title_prefix', 'custom_remove_archive_title_prefix');

    Hope that helps,

    Oliver

    Thread Starter bensontel2

    (@bensontel2)

    Thanks, Oliver. I have not implemented your solution because now I can’t log into the site and the prefixes are back. I commented out the previous solution but it makes no difference. I’m more worried about the error on the login page saying my browser should enable cookies. I’ll have to start another thread on this as I can’t now login to the dashboard.

    Oh dear!

    The cookies error is usually when you go to the site through a different hostname to the default one (without the www. for example) and the site redirects to the correct one during login which breaks the cookies.

    A second login attempt usually gets you in.

    Oliver

    Thread Starter bensontel2

    (@bensontel2)

    I renamed the functions.php to something else and I could log in.

    Thread Starter bensontel2

    (@bensontel2)

    Oliver, your solution works when I’m logged into my site, but not when I’m logged out.

    That’s weird. Where exactly did you put it in functions.php?

    Have you purged your cache (if you have a cache service / plugin)?

    Oliver

    Thread Starter bensontel2

    (@bensontel2)

    functions.php is in my child folder. It does sound like a cache problem because it is working when I’m logged in, so I flushed the cache in the browser, disabled Cloudflare. Maybe it will take a while to stop serving pages. I purged all pages on the site, too.

    Here is the entire contents of the functions.php in the child theme.

    <?php
    function custom_remove_archive_title_prefix($prefix) {
    if ($prefix === 'Category:' || $prefix === 'Tag:') {
    $prefix = '';
    }
    return $prefix;
    }
    add_filter('get_the_archive_title_prefix', 'custom_remove_archive_title_prefix');
    Thread Starter bensontel2

    (@bensontel2)

    Update. It’s working now, even when I’m not logged in. Thanks.

    Great news 🙂

Viewing 12 replies - 1 through 12 (of 12 total)
  • You must be logged in to reply to this topic.