- This topic has 7 replies, 4 voices, and was last updated 5 years, 5 months ago by
Tom.
-
AuthorPosts
-
May 7, 2020 at 9:37 am #1274068
James
I’ve been able to customize my archive/category pages to my liking using the blog module of GP Premium. There’s one last thing I’d like to change on these pages and that is add a single word to the end of each title. I’ve searched but can only find a way to prefix the title. Is there a way to add a suffix (for example using code snippets to add to functions.php)?
This is an example of what I’d like to do:
Category name ==> What I’d like to show as the category title on my archive pages
PPC ==> PPC Services
SEO ==> SEO Services
Digital Marketing ==> Digital Marketing Services
Web Analytics ==> Web Analytics ServicesI don’t want to add “Services” to each category name as it’s kind of redundant when it shows in the category widget in the sidebar for example. I have 20 categories and want to add the same word to the end of each title on archive pages.
Thanks in advance!
May 7, 2020 at 3:14 pm #1274566Tom
Lead DeveloperLead DeveloperHi there,
I believe this is the filter you’re looking for: https://developer.wordpress.org/reference/hooks/get_the_archive_title/
For example:
add_filter( 'get_the_archive_title', function( $title ) { if ( is_category( 'PPC' ) ) { return $title . ' Services'; } return $title; }, 20 );May 8, 2020 at 7:48 am #1275335James
Worked like a dream, thanks. Didn’t realise it was so simple!
May 8, 2020 at 8:04 am #1275493Marcel
Thank you Tom for the snippet. Could I have a hint from your side how to create a prefix instead of a suffix for that?
May 8, 2020 at 9:24 am #1275607Leo
StaffCustomer SupportDoes this work?
add_filter( 'get_the_archive_title', function( $title ) { if ( is_category( 'PPC' ) ) { return 'Services ' . $title; } return $title; }, 20 );May 8, 2020 at 9:46 am #1275663Tom
Lead DeveloperLead DeveloperGotta love filters 🙂
May 9, 2020 at 6:02 am #1276587Marcel
Thank you, Leo. It is working.
Tom, you are right, I am gonna love filters. They are so powerful. One more question I would have: where can I find some documentation to learn about the values of arguments the function accepts. On the snippet provided value is “20”. I would like to understand how to use the correct values.
Thank you very much!May 9, 2020 at 4:52 pm #1277312Tom
Lead DeveloperLead DeveloperThe WordPress documentation for functions is pretty awesome: https://developer.wordpress.org/reference/functions/add_filter/
Let me know if you need more info 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.