Name subcategoryproduct in the meta title

#194576
  • I want Variable for see the Name of subcategoryproduct and all category (not Only primary) in the meta title of the productcategory and in product

Viewing 5 replies - 1 through 5 (of 5 total)
  • I want for mystore.com/category/subcategory/product the title: Name product – Category – subcategory – Name website

    Brian
    Rank Math free

    Hello,

    Thank you for contacting Rank Math and sorry for any inconvenience that might have been caused due to that.

    Unfortunately, we do not have a way to which you can add a variable to the title so as to display both the main category and the sub-category.

    You can only display the primary category using this variable %customterm(product_cat)%.

    If you wish to display the subcategory you may have to create a custom variable for that. You can make use of this filter to help you achieve that:

    /**
     * Filter to add custom variables
     */
    add_filter( 'rank_math/vars/replacements', function( $vars ) {
    	return $vars;
    });

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
    Thank you.

    unfortunately I don’t know how to do it. but instead of a variable it is not possible to do it with a function. Can’t you help me? Or I have to go back to yoast seo that I had abandoned for your plugin

    but if I buy the premium plugin, nothing changes?

    Brian
    Rank Math free

    Hello,

    For this issue, you can only have a custom variable for the subcategories to be displayed in the meta tags when the subcategory is selected as the primary term.

    This is also replicated in the Pro/Premium plugin as we do not have a built-in variable to display the subcategories.

    Here is a sample code to show you how you can create the custom variable for displaying these categories.

    add_action( 'rank_math/vars/register_extra_replacements', function() {
    	rank_math_register_var_replacement(
    		'customterm_child_category',
    		[
    
    			'name'        => esc_html__( 'Child Category.', 'rank-math' ),
    			'description' => esc_html__( 'Child Category Description...', 'rank-math' ),
    			'variable'    => 'customterm_child_category',
    			'example'     => customterm_child_category_callback(),
    		],
    		'customterm_child_category_callback'
    	);
    } );
    
    function customterm_child_category_callback() {
    	global $post;
    	$category = get_the_category();
    	$parent = get_cat_name($category[0]->category_parent);
    		  if (!empty($parent)) { 
    		  	return $parent;
    		  } 
    		  else {
    		  	return $category[0]->cat_name;
    		  }
    	}

    You can use the help of a developer to extend this code to your subcategory set as the parent.

    Hope this helps.
    Thank you.

    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 5 replies - 1 through 5 (of 5 total)

The ticket ‘Name subcategoryproduct in the meta title’ is closed to new replies.