• Resolved theJuls

    (@thejuls)


    When I go into certain categories, there is a page title that says “Category: category_name”, like this:

    https://i.stack.imgur.com/nwUaS.png

    I would like to remove the “Category” from that title.
    I’ve already looked around quite a bit and found nothing that works for me. Most answers say to edit the category.php file which doesn’t exist in the theme I am using or go to archive.php which doesn’t seem to have anything relevant to the category title.

    On archive.php, the only seemingly relevant code that even mentions category is this:

    <?php if ( is_tag() || is_category() || is_tax() ) { ?>
      <div class="archive-description"><?php the_archive_description(); ?></div>
    <?php } ?>

    I don’t think it’s relevant at all to what I am trying to do.

    I have also been told as a response to this question, that I could inc/template-tags.php and change this code:

    if ( is_category() ) {
        $title = sprintf( __( 'Category: %s', 'tesseract' ), single_cat_title( '', false ) );
    }

    Unfortunately, whenever I do this (by either removing ‘Category’ or subbing it for some other word), nothing happens. So either I am missing something, or I need to change it somewhere else.

    So, does anyone know how I can remove the category from the title? By the way, the theme I am using is Tesseract.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Howdy @thejuls,

    You can filter the display of the_archive_title() using the get_the_archive_title hook. Example (add the following to your functions.php):

    add_filter( 'get_the_archive_title', function ($title) {
    
        if ( is_category() ) {
            $title = single_cat_title( '', false );
        }
        return $title;
    
    });

    I would also highly recommend creating a child theme for your changes. If you are editing the theme directly, you will lose your changes when it updates.

    Thread Starter theJuls

    (@thejuls)

    Hello!
    Thanks for your help, unfortunately I think I may have fucked up =/

    I went to test the code, and surprise surprise I get
    Parse error: syntax error, unexpected T_FUNCTION in /home/topnewsr/public_html/wp-content/themes/TESSERACT/functions.php on line 1054

    And now, the entire site is down giving me that message and I can’t even go back to remove the line of code ?? I guess I really really screwed up here and am panicking a bit.

    Also, as for the child theme, thank you so much for directing me to that. I am actually quite new with wordpress and was concerned about what to do whenever theme updates come in.

    Thread Starter theJuls

    (@thejuls)

    Update: after taking a deep breath, managed to re-upload the functions.php file to get things back working, unfortunately that still means I don’t know how to fix the problem ??

    Interesting.. I dropped that right at the bottom of my functions.php with Tesseract theme active and it worked fine. You could also try it this way.

    add_filter( 'get_the_archive_title', 'remove_archive_title_prefix', 10, 1 );
    
    function remove_archive_title_prefix( $title ) {
    
        if ( is_category() ) {
    
            $title = single_cat_title( '', false );
    
        }
    
        return $title;
    
    }
    Thread Starter theJuls

    (@thejuls)

    Now, yes, worked beautifully.

    Thank you so much for all your help ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘How to remove category titles?’ is closed to new replies.