-
Hello,
I am looking for guidance on how to populate ‘product tags’ into the meta description editor.
I would appreciate any examples or resources you could share.
Thank you for your time and assistance. I look forward to your response.
Best regards,
Hindistack
-
Hello,
We apologize for the issue you are facing. Unfortunately, the context provided does not include specific instructions on how to populate WooCommerce product tags into the meta description editor.
We recommend replying to this ticket with your request, and a human agent from the Rank Math Support team will be able to assist you further with detailed guidance or examples.
Thank you for raising this concern, and we appreciate your understanding!
This is an automated reply from Rank Math Support Bot. Your ticket has been assigned to a human agent and we will get back to you shortly.
Hello,
I tried this with AI, but I am facing a critical site issue.
Please check this code and let me know how I can fix it./** * Register custom Rank Math variables for WooCommerce product tags. */ add_action('rank_math/vars/register_extra_replacements', function () { // Register basic WooCommerce product tags variable. rank_math_register_var_replacement( 'wc_tags', [ 'name' => esc_html__('Product Tags', 'rank-math'), 'description' => esc_html__('Displays tags of the current WooCommerce product.', 'rank-math'), 'variable' => 'wc_tags', 'example' => wc_tags_callback(), ], 'wc_tags_callback' ); // Register advanced WooCommerce product tags variable. rank_math_register_var_replacement( 'wc_tags_advanced', [ 'name' => esc_html__('Product Tags (Advanced)', 'rank-math'), 'description' => esc_html__('Displays WooCommerce product tags with options like limit, separator, and exclude.', 'rank-math'), 'variable' => 'wc_tags_advanced(limit=3&separator= | &exclude=12,23)', 'example' => wc_tags_advanced_callback('limit=3&separator= | &exclude=12,23'), ], 'wc_tags_advanced_callback', true // Allows passing dynamic parameters. ); }); /** * Basic Product Tags Callback Function. */ function wc_tags_callback() { if (function_exists('wc_get_product') && is_product()) { $product_id = get_the_ID(); // Get the current product ID. $tags = wp_get_post_terms($product_id, 'product_tag', ['fields' => 'names']); // Fetch product tags. return !empty($tags) ? implode(', ', $tags) : esc_html__('No Tags', 'rank-math'); // Return tags or fallback. } return esc_html__('Not a Product Page', 'rank-math'); // Fallback for non-product pages. } /** * Advanced Product Tags Callback Function. * * @param string $options Options string in the format <code>limit=3&separator= | &exclude=12,23</code>. * @return string Formatted product tags based on the given options. */ function wc_tags_advanced_callback($options = '') { if (!function_exists('wc_get_product') || !is_product()) { return esc_html__('Not a Product Page', 'rank-math'); } // Parse options $options = trim(str_replace(['wc_tags_advanced(', ')'], '', $options)); // Remove variable wrapping. parse_str($options, $args); // Default values $limit = isset($args['limit']) ? (int) $args['limit'] : 0; $separator = isset($args['separator']) ? $args['separator'] : ', '; $exclude = isset($args['exclude']) ? array_map('intval', explode(',', $args['exclude'])) : []; // Get product tags $product_id = get_the_ID(); $tags = wp_get_post_terms($product_id, 'product_tag', ['fields' => 'all']); if (is_wp_error($tags)) { return esc_html__('Error fetching tags', 'rank-math'); } // Filter excluded tags if (!empty($exclude)) { $tags = array_filter($tags, function ($tag) use ($exclude) { return !in_array($tag->term_id, $exclude, true); }); } // Limit tags if ($limit > 0) { $tags = array_slice($tags, 0, $limit); } // Format tag names $tag_names = wp_list_pluck($tags, 'name'); return !empty($tag_names) ? implode($separator, $tag_names) : esc_html__('No Tags', 'rank-math'); }
Hello,
Can you please confirm if you want to use the product tags on the product meta description? If so, for the tag title, you can use
%customterm(product_tag)%
and for the tag description, you can use%customterm_desc(product_tag)%
variables in the meta description field.However, please note that the variables may not be visible while editing the products as it only works when your products load in a browser. You can check the published/saved product’s meta description via its source code.
Let us know how it goes. Looking forward to helping you.
Thank you.
You must be logged in to reply to this ticket.