Variable to get Term Slug in Category SEO Setting

#154378
Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for the delay.

    You can use this filter on your theme’s functions.php file to register a %category_slug% variable

    add_action( 'rank_math/vars/register_extra_replacements', function(){
    	rank_math_register_var_replacement(
    	   'category_slug',
    	   [
    	   'name'        => esc_html__( 'Category Slug', 'rank-math' ),
    	   'description' => esc_html__( 'return category slug', 'rank-math' ),
    	   'variable'    => 'category_slug',
    	   'example'     => category_slug_callback(),
    	   ],
    	   'category_slug_callback'
       );
    });
    function category_slug_callback(){
    	$tag_ID = $_GET["tag_ID"];
    	$catinfo = get_term($tag_ID);
    	$categoryslug = $catinfo->slug;
    	return $categoryslug;
    }

    You can search Category slug in the drop-down list, or you can use the %category_slug% variable directly.

    I hope that helps. Thank you, and looking forward to your update.

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

The ticket ‘Variable to get Term Slug in Category SEO Setting’ is closed to new replies.