-
How can I enable wordCount in schema..
I used %wordCount% and %content%
%character%
Is not working
-
Hello,
Thank you so much for getting in touch.
Those variables are not available in our plugin. Can you please confirm if the variable
%wordcount%
will be the word count of your post/page content? If so, you would need to create a custom variable for that.Please refer to the steps here on how to add custom variable: https://rankmath.com/kb/variables-in-seo-title-description/#how-to-add-custom-variables
This applies to the rest of the variables you have mentioned.
Hope that helps and please do not hesitate to let us know if you need my assistance with anything else.
I’m talking about variable in Article schema
Pls can you just send me one single script ” like this “/**
* 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(
‘term_count’,
[
‘name’ => esc_html__(‘Term Count’, ‘rank-math’),
‘description’ => esc_html__(‘Number of posts in the current term’, ‘rank-math’),
‘variable’ => ‘term_count’,
‘example’ => term_count_callback(),
],
‘term_count_callback’
);
});
function term_count_callback()
{
$term = get_queried_object();
return isset($term) ? $term->count : null;
}that I will add to my theme functions.php which will contains
1. ArticleBody
2. wordcount
3. alternativeHeadline
4. mainEntityofPageOr the one that will just continue only
1. ArticleBody
2. wordcountHello,
You need to create a separate function for another variable. For example, if you wish to get the word count of your content, you need to make a new instance of a custom variable function. Please refer to the code below:
add_action('rank_math/vars/register_extra_replacements', function () { rank_math_register_var_replacement( 'term_count', [ 'name' => esc_html__('Term Count', 'rank-math'), 'description' => esc_html__('Number of posts in the current term', 'rank-math'), 'variable' => 'term_count', 'example' => term_count_callback(), ], 'term_count_callback' ); }); function term_count_callback() { $term = get_queried_object(); return isset($term) ? $term->count : null; } add_action('rank_math/vars/register_extra_replacements', function () { rank_math_register_var_replacement( 'word_count', [ 'name' => esc_html__('Term Count', 'rank-math'), 'description' => esc_html__('Number of posts in the current term', 'rank-math'), 'variable' => 'word_count', 'example' => word_count_callback(), ], 'word_count_callback' ); }); function word_count_callback() { global $post; $post_id = $post->ID; $content = get_post_field('post_content', $post_id); $word_count = str_word_count(strip_tags($content)); return $word_count; }
Hope that helps and please do not hesitate to let us know if you need my assistance with anything else.
Thanks
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.
The ticket ‘wordCount’ is closed to new replies.