Okay
  Public Ticket #2954109
Remove "Category /" from Blog Category Page
Closed

Comments

  •  1
    nicholaspaoli started the conversation

    Hi.

    How can I remove the word "Category" from the title of my archive pages? Using the code snippet below in the functions.php of Child Theme didn't work

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

    and Kalium Blog Settings only allows to show or hide the whole title. Please see the screenshot attached, since my website is still in Staging mode.

    Thanks in advance.

  • [deleted] replied

    Hi Nicholas,

    Please add this PHP code on your functions.php file of your Child theme.

    function kalium_blog_page_header() {
        // Args
        $args = [];
        if ( kalium_blog_get_option( 'loop/header/show' ) ) {
            $args['heading_tag'] = 'h1';
            $queried_object = get_queried_object();
            $title          = kalium_blog_get_option( 'loop/header/title' );
            $description    = kalium_blog_get_option( 'loop/header/description' );
            // Description from post content
            if ( is_home() && ! empty( $queried_object->post_content ) ) {
                $description = apply_filters( 'the_content', $queried_object->post_content );
            }
            // Category, tag and author pages show custom title
            if ( apply_filters( 'kalium_blog_page_heading_replace_for_taxonomies', true ) ) {
                $separator = apply_filters( 'kalium_blog_page_heading_replace_for_taxonomies_separator', ' / ' );
                // Category
                if ( is_category() ) {
                    if ( apply_filters( 'kalium_blog_page_header_last_category_title_only', false ) ) {
                        $categories = single_cat_title( '', false );
                    } else {
                        $categories = get_the_category_list( $separator );
                    }
                    $title       = $categories;
                    $description = category_description( $queried_object->object_id );
                } // Tag
                else if ( is_tag() ) {
                    $tag         = single_term_title( '', false );
                    $title       = sprintf( '%s %s %s', esc_html__( 'Tag', 'kalium' ), $separator, $tag );
                    $description = tag_description( $queried_object->object_id );
                } // Author
                else if ( is_author() ) {
                    $author       = get_user_by( 'id', get_queried_object_id() );
                    $display_name = $author instanceof WP_User ? $author->display_name : get_the_author();
                    $title        = sprintf( '%s %s %s', esc_html__( 'Author', 'kalium' ), $separator, $display_name );
                    $description  = get_the_author_meta( 'description' );
                } // Year
                else if ( is_year() ) {
                    $title       = sprintf( '%s %s %s', esc_html__( 'Year', 'kalium' ), $separator, get_the_date( 'Y' ) );
                    $description = '';
                } // Month
                else if ( is_month() ) {
                    $title       = sprintf( '%s %s %s', esc_html__( 'Month', 'kalium' ), $separator, get_the_date( 'F Y' ) );
                    $description = '';
                } // Day
                else if ( is_day() ) {
                    $title       = sprintf( '%s %s %s', esc_html__( 'Month', 'kalium' ), $separator, get_the_date( 'F j, Y' ) );
                    $description = '';
                }
            }
            // Title and description
            $args['title']       = $title;
            $args['description'] = $description;
            // When there is WPBakery content in description show without page-heading template
            if ( false !== strpos( $description, 'vc_row' ) ) {
                echo $description;
            } else {
                // Page heading template
                kalium_page_heading( $args );
            }
        }
    }

    Have a nice day!

  •  1
    nicholaspaoli replied

    Thank you Ylli. I added that code on my functions.php file of my Child theme but unfortunately nothing happened. Even by adding it on the main theme it just hides everything on the page. What am I wrong?

  • [deleted] replied

    Hi Nicholas,

    Please share your WordPress credentials, because I need to login to your site and test this live.

    To include your credentials click the Insert Credentials button in the editor toolbar (see how) so your reply will be private.

    Thanks!

  •   nicholaspaoli replied privately
  • [deleted] replied

    I've made a change in main files of Kalium, more exactly changed this file: kalium/includes/functions/template/blog-template-functions.php (download https://d.pr/f/Kgw3Fs).

    Then I added this code in functions.php:

    // Remove Category prefix
    add_filter( 'kalium_blog_page_header_show_category_prefix', '__return_false' );

    And the category prefix is removed (see screenshot]).

    Please note that the new version of file that I replaced (blog-template-functions.php) will be included in future kalium updates to provide support for optional remove of category prefix from page heading.

    Have a nice day!

  •  1
    nicholaspaoli replied

    Thanks a lot!

    Have a great day.

  • [deleted] replied

    I'm happy I helped Nicholassmile.png

    I wish you all the best!

    P.S: If you enjoy our theme, you can head over to your Downloads tab and give it 5 stars. We will love you forever.

  •   nicholaspaoli replied privately
  • [deleted] replied

    Hi Nicolas,

    You just need to add this code in functions.php file:

    // Remove Category prefix
    add_filter( 'kalium_blog_page_header_show_category_prefix', '__return_false' );

    Thanks!