How to import h2 subtitle information into the meta tags?

#202272
  • Resolved HornTech NZ
    Rank Math free

    There are 2 titles in my product webpage:
    <h1 itemprop="name" class="product_title entry-title">TC-6601R</h1>
    <h2 class="single-product-subtitle">ZODIAC Back to Wall Rimless Cleanflush Close Coupled Toilet Suite</h2>

    There is a syntax %title% in rankmath title & meta section to crawl the product title. However, I hope to display the subtitle content as the meta title in Google search result. How can I do that?

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

    Thanks for contacting us.

    You must be using a plugin to add a subtitle to your products. As it is not something being added by WooCommerce or WordPress, there is no predefined variable that you can use to show subtitles in the SEO title.

    However, you can create a new variable that saves the value of the subtitle in it and use that in the Titles & Meta settings. To create a new variable, please copy and modify the code given below and then paste it into your theme’s/child theme’s functions.php file:

    /**
     * Action: 'rank_math/vars/register_extra_replacements' - Allows adding extra variables.
     */add_action( 'rank_math/vars/register_extra_replacements', function(){
     rank_math_register_var_replacement(
     'custom_variable_slug',
     [
     'name'        => esc_html__( 'Custom variable name.', 'rank-math' ),
     'description' => esc_html__( 'Custom variable description.', 'rank-math' ),
     'variable'    => 'custom_variable_slug',
     'example'     => 'custom_variable_callback()',
     ],
     'custom_variable_callback()'
     );
    });

    Hope this helps. Let us know if you need any further assistance.

    Thanks for replying. As I am not familiar with JS and WP syntax, so can you help to define the value of custom_variable_slug and custom_variable_callback() for subtitle as an example pls? That could be cleaner for me to use it. Thanks a lot!

    Hello,

    Before doing so, could you please confirm if are you using a custom field for your subtitle (H2), or are you directly adding it to your content?

    We are looking forward to helping 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 3 replies - 1 through 3 (of 3 total)

The ticket ‘How to import h2 subtitle information into the meta tags?’ is closed to new replies.