Hello,
Thank you for contacting Rank Math today.
You can create a custom var that gets the number of posts in the current category by using the following filter:
/**
* Filter to add custom variables
*/
add_filter( 'rank_math/vars/replacements', function( $vars ) {
return $vars;
});
Looking forward to helping you. Thank you.
Hey Alberto
Thanks for your quick reply.
I actually found a post looking for similar help, right after I posted this.
https://support.rankmath.com/ticket/code-for-categories/
Although I’m still having no joy with the suggested variable on that link.
It looks as if it calculating all posts instead of each category and stripping out the rest of the title.
Hi Carlo,
You have to pay attention to this line:
'post_type' => 'post' //assign the post type name
Change it to the post type name.
Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.
Thanks for replying Todd.
Yeah the post type is ‘post’.
If I add in the category number e.g
'post_type' => 'post',
'cat' => '36'
this then correctly pulls in the total number of posts in the category into the title, but then I want this for more than 1 category. Also, it only shows the number in the title, not the title that’s been set up in the category?
Hello,
Thank you for contacting Rank Math today.
The code on the other thread will create a custom title on category pages.
I can suggest that you customize this line return $number." "."Egg Recipes";
with the actual title that you want to display on the pages.
If you want to use this on posts then you will also need to replace this conditional with another suitable one:
if(is_category()){
Looking forward to helping you. Thank 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.