Title: dashingzahi's Replies | WordPress.org

---

# dashingzahi

  [  ](https://wordpress.org/support/users/dashingzahi/)

 *   [Profile](https://wordpress.org/support/users/dashingzahi/)
 *   [Topics Started](https://wordpress.org/support/users/dashingzahi/topics/)
 *   [Replies Created](https://wordpress.org/support/users/dashingzahi/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/dashingzahi/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/dashingzahi/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/dashingzahi/engagements/)
 *   [Favorites](https://wordpress.org/support/users/dashingzahi/favorites/)

 Search replies:

## Forum Replies Created

Viewing 1 replies (of 1 total)

 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[Rank Math SEO – AI SEO Tools to Dominate SEO Rankings] Custom Single Title based on Category](https://wordpress.org/support/topic/custom-single-title-based-on-category/)
 *  [dashingzahi](https://wordpress.org/support/users/dashingzahi/)
 * (@dashingzahi)
 * [2 years, 3 months ago](https://wordpress.org/support/topic/custom-single-title-based-on-category/#post-17406232)
 * To achieve this with RankMath, you can use the following code snippet in your
   theme’s functions.php file or a custom plugin:
 * phpCopy code
 * `function custom_rankmath_seo_title( $title, $id ) { // Get the post object $
   post = get_post( $id ); // Check if it's a single post if ( is_singular( 'post')&&!
   empty( $post ) ) { // Get the post categories $categories = get_the_category(
   $post->ID ); // Check if the post has categories if ( $categories ) { // Loop
   through categories and check for specific ones foreach ( $categories as $category){
   switch ( $category->name ) { case 'Cars': $title = 'How to Drive a %title% %sep%%
   sitename%'; break; case 'Recipes': $title = 'Cooking %title% Recipe %sep% %sitename%';
   break; case 'Phones': $title = 'How to Buy %title% %sep% %sitename%'; break; //
   Add more cases for other categories as needed } } } } return $title; } add_filter('
   rank_math/frontend/title', 'custom_rankmath_seo_title', 10, 2 );`
 * This code uses the `rank_math/frontend/title` filter hook to modify the SEO title
   dynamically based on the post category. Adjust the category names and title formats
   as per your specific needs. You can add more cases for other categories following
   the same pattern.
 * Remember to test this code in a safe environment first, and always have a backup
   of your code before making changes.
   I am using same method for my [tesla homes](https://teslahomesguide.com)
   blog.

Viewing 1 replies (of 1 total)