Modify Category,Tag Title with Count

#52787
  • Resolved Ranuka
    Rank Math free

    I want to add “count” for all category, tag titles. Is there any filter for it?

    Eg: Current title of SEO Category is “SEO Tips“. If the SEO category includes 50 posts, I want to modify the title as “50 SEO Tips“.

    Is there any filter for it. I checked https://rankmath.com/kb/filters-hooks-api-developer/, can be used “rank_math/frontend/title” filter for my purpose?

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math today.

    I can suggest that you create a unique title by registering some custom PHP code to register a custom category title on your theme’s functions.php file.

    Here is an example to get the total count of the current posts on the site and return the value on the category title:

    /**
     * Filter to change the Rank Math category page title.
     * 
     * @param string $title
     */
    add_filter( 'rank_math/frontend/title', function( $title ) {
    	if(is_category()){
    		$my_posts = get_posts(array(
    	         'posts_per_page'	=> -1,
    	         'post_type'		=> 'post' //assign the post type name here
                  ));
    		$number = count($my_posts);
    		return $number." "."SEO Tips";
    	}
    	return $title;
    });

    I hope this info helps. 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.

Viewing 1 replies (of 1 total)

The ticket ‘Modify Category,Tag Title with Count’ is closed to new replies.