Title of product category pages that adapts with the filter selected

#640695
Viewing 9 replies - 1 through 9 (of 9 total)
  • Hello,

    Thank you for contacting Rank Math. We are sorry for the trouble this may have caused you.

    Can you please check if you have properly added the code to your website? You may follow this guide: https://rankmath.com/kb/wordpress-hooks-actions-filters/.

    Also, please make sure that the query parameters (for example, filter_brand) match to the parameters on your category archive page.

    For us to check further, please share an example of your category page URL with filtering enabled.

    Looking forward to helping you with this one.

    Hello,

    thank you very much for your reply. I have the code in child theme functions.php
    This is how it looks:

    add_filter( 'rank_math/frontend/title', function( $title ) {
        if( is_product_category() ) {
            $filter_znacka = $_GET['filter_znacka'];
            $filter_farba = $_GET['filter_farba'];
    		$space = ' ';
            
            if ( isset($filter_znacka) ) {
                $title = $filter_znacka . $space . $title;
            }
    
            if ( isset($filter_farba) ) {
                $title = $filter_farba . $space . $title;
            }
        }
        return $title;
    });

    For example filter_farba (means in English filter_color). Im sending an example with products filtered by color black: https://mydecor.sk/k/kresla/?filter_farba=cierna&query_type_farba=or

    But the title didnt adapt with the color filter.

    Appreciate your assistance, dont know what the issue might be.

    Best regards,
    Ivana

    Hello,

    Thank you for your patience.

    Upon checking the link you shared, the color “cierna” is already added before the title.

    <title>cierna Kreslá - My Decor</title>

    You can also verify that using this tool:
    https://rankmath.com/tools/meta-tag-analyzer/

    Could you please confirm if you’re seeing different results?

    Looking forward to helping you.

    MyDecor
    Rank Math free

    OMG, thank you very much, I dont know why I supposed to think that it also changes the title of product category page in archive pages, but now I see it changes the meta tags 🙂

    I have made some edits to code so it is in line with Slovak language eg. Furniture in color black.. etc. But I get critical error. Can you please advise me?

    
    add_filter( 'rank_math/frontend/title', function( $title ) {
        if( is_product_category() ) {
            $filter_znacka = $_GET['filter_znacka'];
            $filter_farba = $_GET['filter_farba'];
    		$filter_material = $_GET['filter_material'];
    		$znacky = ' značky ';
    		$vofarbe = ' vo farbe ';
    		$zmaterialu = ' z materiálu ';
            
            if ( isset($filter_znacka) ) {
                $title = $title . $znacky . $filter_znacka;
            }
    
            if ( isset($filter_farba) ) {
                $title = $title . $vofarbe . $filter_farba;
            }
    		
    		if ( isset($filter_material) ) {
                $title = $title . $zmaterialu . $filter_material;
        }
        return $title;
    });
    

    Thank you for your patience.
    Best regards,
    Ivana

    Hello,

    From your code, it seems that there’s a missing semicolon at the end.

    Please add a closing semicolon at the last line like this:

    }});
    

    Let us know how this goes.

    MyDecor
    Rank Math free

    Hi Reinelle,
    that worked, thank you so much! 🙂

    I have one more question though: All of my meta titles are lowercase even though they are originaly written with first letter capital. I found an option in Rank Math SEO settings to capitalize each word, but I would like to capitalize only first letter.
    For example:
    Original title in my website: Wooden tables
    actual meta title: wooden tables
    option in settings: Wooden Tables
    My preferable solution: Wooden tables (just like original title)

    Thank you very much for helping me out.

    Best regards,
    Ivana

    Hello,

    To set the first word to be a capital letter you need to modify the filter further and update the lines where you set the $title variable like so:

    
    $title = ucfirst( $title . $znacky . $filter_znacka );
    

    The example above is for the first time the variable is set but you can apply the same structure by wrapping the data into the function ucfirst() for the other 2 below that as well.

    Don’t hesitate to get in touch if you have any other questions.

    MyDecor
    Rank Math free

    Hi,
    thank you for your reply. That worked 🙂
    One last question – is there a way of how to show diacritis (special characters like ľ,š,č etc) in SEO meta title. For now the $filter_material is not showing those characters (it turns š to s, č to c etc.).

    The code is now looking like this, working perfectly, except diacritics in $filter_material. For color filter I set conditions for example turn “Modra” to “Modré” so it has diacritics but I have 100+ different materials so I prefer not to do it manually.

    add_filter( 'rank_math/frontend/title', function( $title ) {
        if( is_product_category() ) {
            $filter_znacka = $_GET['filter_znacka'];
            $filter_farba = $_GET['filter_farba'];
    		$filter_material = $_GET['filter_material'];
    		$znacky = ' ';
    		$vofarbe = ' ';
    		$zmaterialu = ' - ';
            
            if ( isset($filter_znacka) ) {
                $title = ucfirst( $filter_znacka . $znacky . lcfirst ($title ));
            }
    
            if ( isset($filter_farba) ) {
    			$farba = strtolower($filter_farba);
    			switch($farba){
    				case 'cierna':
    					$filter_farba = 'Čierne';
    					break;
    				case 'zlata':
    					$filter_farba = 'Zlaté';
    					break;
    				case 'siva':
    					$filter_farba = 'Sivé';
    					break;
    				case 'zelena':
    					$filter_farba = 'Zelené';
    					break;
    				case 'strieborna':
    					$filter_farba = 'Strieborné';
    					break;
    				case 'ruzova':
    					$filter_farba = 'Ružové';
    					break;
    				case 'hneda':
    					$filter_farba = 'Hnedé';
    					break;
    				case 'modra':
    					$filter_farba = 'Modré';
    					break;
    				case 'biela':
    					$filter_farba = 'Biele';
    					break;
    				case 'oranzova':
    					$filter_farba = 'Oranžové';
    					break;
    				case 'zlta':
    					$filter_farba = 'Žlté';
    					break;
    				case 'prirodna':
    					$filter_farba = 'Prírodné';
    					break;
    				case 'bezova':
    					$filter_farba = 'Béžové';
    					break;
    				case 'priehladna':
    					$filter_farba = 'Priehľadné';
    					break;
    				case 'farebna':
    					$filter_farba = 'Farebné';
    					break;
    				case 'fialova':
    					$filter_farba = 'Fialové';
    					break;
    				case 'cervena':
    					$filter_farba = 'Červené';
    					break;
    				case 'tyrkysova':
    					$filter_farba = 'Tyrkysové';
    					break;
    				default:
    					$filter_farba = ucfirst($filter_farba);
    					break;
    			}
                $title = ucfirst( $filter_farba . $vofarbe . lcfirst( $title ));
            }
    		
    		if ( isset($filter_material) ) {
                $title = ucfirst( $filter_material . $zmaterialu . $title );
        }
        return $title;
    }});

    Thank you for your patience and helping me out.

    Best regards,
    Ivana

    Hello,

    Unfortunately, we cannot fetch the diacritics from the URL directly because the URL already strips them before we read the data from there.

    For this to work with the diacritics the implementation would need to be different and much more complex. The data inside the filter would need to parse the query parameter and fetch the actual title with the diacritics from the database.

    Don’t hesitate to get in touch if you have any other questions.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 9 replies - 1 through 9 (of 9 total)

The ticket ‘Title of product category pages that adapts with the filter selected’ is closed to new replies.