Home › Forums › Support › How to add a prefix to the Category Title for certain parent category ? This topic has 6 replies, 3 voices, and was last updated 3 years, 3 months ago by Tom. Viewing 7 posts - 1 through 7 (of 7 total) Author Posts January 27, 2021 at 10:31 am #1636012 Budi Hello, I want to add prefix for subcategory which has parent category name=xxx or id=xxx I tried below code, but not worked. add_filter( ‘get_the_archive_title’, function( $title ) { $category = get_the_category(); $category_parent_id = $category[0]->category_parent; if ( $category_parent_id = 10 ) { $title = ‘Prefix ‘. $title; } return $title; }, 50 ); Thanks. January 27, 2021 at 6:37 pm #1636313 ElvinStaff Customer Support Hi there, You can try this instead: add_filter( 'get_the_archive_title', function( $title ) { $archive_cat = get_queried_object(); if ($archive_cat->category_parent == 83) { $title = 'Prefix '. $title; } return $title; }, 50 ); January 27, 2021 at 8:10 pm #1636385 Budi Thanks, it works perfectly. Can you explain about the value 50 ? In some answers, I saw the value is 20. January 28, 2021 at 7:20 am #1637130 Budi Hello, I also want to add a prefix to the Tag Title on tag archive. What code should I insert for below code ? add_filter( ‘get_the_archive_title’, function( $title ) { $archive_cat = get_queried_object(); if ($archive_cat->category_parent == 83) { $title = ‘Prefix ‘. $title; } return $title; }, 50 ); Thanks. January 28, 2021 at 3:20 pm #1637595 ElvinStaff Customer Support Try this: add_filter( 'get_the_archive_title', function( $title ) { $archive_cat = get_queried_object(); $tags = get_the_tags(get_queried_object()->ID); if ($archive_cat->category_parent == 83) { $title = 'Prefix '. $title; } if ($tags) { foreach($tags as $tag) { if ($tag->slug == 'test') { $title = 'Prefix '. $title; } } } return $title; }, 50 ); January 29, 2021 at 11:00 am #1638700 Budi The prefix I want to add for the tag title is in tags archives, not tags in category archives. Url example: http://www.generatepress.com/tag/flower January 30, 2021 at 10:42 am #1639754 TomLead Developer Lead Developer The code should be almost identical to the original code that worked. The only difference I can see is you’d use parent instead of category_parent: https://dev.to/ko31/return-value-of-getqueriedobject-in-wordpress-1h7n These kinds of general WordPress coding questions are far better suited for a site like this: https://wordpress.stackexchange.com/ Thanks! Author Posts Viewing 7 posts - 1 through 7 (of 7 total) You must be logged in to reply to this topic. Log In Username: Password: Keep me signed in Log In