“Taxonomy Meta” in SEO Titles

#354633
  • Resolved Pragya
    Rank Math free

    Hi,

    We would like to include the value of ‘Taxonomy meta’ in the SEO title.

    Can see the options to include custom field and custom terms and was wondering if its possible to show custom meta as well.

    Thanks

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

    Thanks for contacting us and sorry for any inconvenience that might have been caused due to that.

    Can you please confirm if you want to add the name of the taxonomy in the SEO title? If yes then you can use %customterm(tern-name)% variable in the meta field.

    Let us know how that goes. Looking forward to helping you.

    Pragya
    Rank Math free

    Hi,

    Its not the name of the taxonomy but the value of ‘Taxonomy meta’.

    Regards

    Hello,

    In this case, you would need to create a custom variable to which you can assign your taxonomy meta.

    If I understand you correctly, you need to make use of this WordPress function get_term_meta() to retrieve the taxonomy meta and assign it to the custom variable. Then insert the custom variable into the SEO title.

    /**
    * Action: 'rank_math/vars/register_extra_replacements' - Allows adding extra variables.
    * Snippet to register variable that will return all terms in custom taxonomy
    */
    add_action( 'rank_math/vars/register_extra_replacements', function(){
    	rank_math_register_var_replacement(
    	   'shortcode_var_name', [
    	   'name'        => esc_html__( 'Author name', 'rank-math' ),
    	   'description' => esc_html__( 'Author description', 'rank-math' ),
    	   'variable'    => 'shortcode_var_name', /* the actual variable: %shortcode_var_name% */
    	   'example'     => shortcode_var_name_call_back(),
    	   ],
    	   'shortcode_var_name_call_back'
       );
    });
    function shortcode_var_name_call_back(){
    	return "your value here...";
    }

    You can then insert the variable %shortcode_var_name% to the SEO Title.

    Let me know if this helps you with your situation. Looking forward to helping you.

    Pragya
    Rank Math free

    Hi Jeremy,

    My coding skills are not that great.

    The name of the taxonomy meta i need to use in the seo title is brand_heading.

    Where should i include that in the above code.

    Thanks

    Hello,

    Please try the below code in your theme’s functions.php file or use the Code Snippets plugin:

    add_action( 'rank_math/vars/register_extra_replacements', function(){
    	rank_math_register_var_replacement(
    	   'mytermtitle', [
    	   'name'        => esc_html__( 'Author name', 'rank-math' ),
    	   'description' => esc_html__( 'Author description', 'rank-math' ),
    	   'variable'    => 'mytermtitle', /* the actual variable: %mytermtitle% */
    	   'example'     => mytermtitle_call_back(),
    	   ],
    	   'mytermtitle_call_back'
       );
    });
    function mytermtitle_call_back(){
        $brand_txt = "";
        if(is_tax()){
            $queried_object = get_queried_object();
            $term_id = $queried_object->term_id;
            $brand_txt = get_term_meta($term_id, 'brand_heading', true);
        }
    
    	return $brand_txt;
    }

    After applying the code, you can make use of the custom %mytermtitle% variable.

    Let us know if that works from your end. Looking forward to helping you.

    Pragya
    Rank Math free

    This worked like a charm. Thanks a ton.

    Hello,

    We are super happy that this resolved your issue. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind me asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you do have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

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

The ticket ‘“Taxonomy Meta” in SEO Titles’ is closed to new replies.