Problem with variable tegory% in SEO title

#662198
  • Resolved IMK
    Rank Math free

    Hello,

    I have added the %category% variable in the meta title settings, however nothing appears.

    I noticed that this is a CPT that comes within the theme itself, to be specific a portfolio. I deduce that for that reason, the category of the portfolio is not shown.

    Is there any way to show the portfolio category variable in the SEO title?

    Thanks in advance

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for the delay and for any inconvenience this issue may have caused you.

    The %category% variable is only used for post types.

    In this case, you may try using the %term% or %customterm(taxonomy-name)% variables on your meta title.

    Here’s a link for more information about variables:
    https://rankmath.com/kb/variables-in-seo-title-description/

    Hope that helps.

    Thank you.

    IMK
    Rank Math free

    Thank you for your response.

    I have added the variables you mention but they don’t work.

    However, I tried the following code and it did work. I share it in case any user might be interested.

    /**
     * Action: 'rank_math/vars/register_extra_replacements' - Allows adding extra variables.
     * Snippet to register variable that will return the number of posts in the current term
     */
    add_action('rank_math/vars/register_extra_replacements', function () {
        rank_math_register_var_replacement(
            'portfolio_category',
            [
                'name'        => esc_html__('Category Portfolio', 'rank-math'),
                'description' => esc_html__('Category Portfolio Description', 'rank-math'),
                'variable'    => 'portfolio_category',
                'example'     => portfolio_category_callback(),
            ],
            'portfolio_category_callback'
        );
    });
    function portfolio_category_callback()
    {
        $term = get_queried_object();
    	$idPost=$term->ID;
    	$current_term = get_the_terms( $idPost, 'portfolio_category' );
    	
        return isset($current_term) ? $current_term[0]->name : '';
        
    }

    Best regards

    Hello,

    Thank you for the update.

    We appreciate you sharing the filter to register the taxonomy as a variable.

    If you have any other concerns, please don’t hesitate to contact us anytime to assist you further.

    Looking forward to helping you.

    Thank you.

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

The ticket ‘Problem with variable tegory% in SEO title’ is closed to new replies.