- This topic has 7 replies, 2 voices, and was last updated 8 years, 2 months ago by
Tom.
-
AuthorPosts
-
February 4, 2018 at 3:24 pm #488026
Denise
Hello GP Friends,
I would like to modify the page title for all category and tag archives.
— for categories, append the words ‘Resource Type: ‘ before the title
– for tags, append the word ‘Topic: ‘ before the title
For example:
If the archive is a category called Videos, I would like the page title to be: ‘Resource Type: Videos’
If the archive is a tag called Healthcare, I would like the page title to be ‘Topic: Healthcare’Can I do this with a hook and filter using generate_archive_title?
I’m using a child theme, with GP Pro.Thanks,
DeniseFebruary 4, 2018 at 10:50 pm #488140Tom
Lead DeveloperLead DeveloperHi there,
You should be able to use this filter:
get_the_archive_titleFor example:
add_filter( 'get_the_archive_title', 'tu_adjust_archive_titles', 20 ); function tu_adjust_archive_titles( $title ) { if ( is_tag() ) { return 'Topic: ' . single_tag_title( '', false ); } if ( is_category() ) { return 'Resource Type: ' . single_cat_title( '', false ); } return $title; }Hope this helps 🙂
February 5, 2018 at 5:00 pm #488975Denise
Hi Tom,
Thanks for the code. That’s the same as what I was trying to use, but I can’t get it to work.
I tested it on my staging site on a bare bones install with GP Pro, a child theme, no pluginis, nothing in the css, and only your code in the functions.php. It didn’t change the archive title. The regular archive heading with just the tag (or category) word was displayed, as it usually is.However, if I put similar code in the GP Hooks, after the heading, it does show up, so something is working:
<?php
if ( is_tag() ) {
echo ‘Topic: ‘ . single_tag_title( ”, false );
}if ( is_category() ) {
echo ‘Resource Type: ‘ . single_cat_title( ”, false );
}
?>I wonder if it has to do with settings in the customizer? I played around with changing them, but it didn’t change anything. Then I tried playing with the permalinks, but that had no affect.
Thanks for your help,
DeniseFebruary 5, 2018 at 5:18 pm #488978Denise
Is it possible that I need to remove a filter before applying the new one?
Thanks,
DeniseFebruary 5, 2018 at 8:36 pm #489077Tom
Lead DeveloperLead DeveloperDid you add it to a child theme? I just made an adjustment above – let me know if it works now 🙂
February 5, 2018 at 8:54 pm #489081Denise
Hi Tom,
I see you added the second parameter (20).
I tried it and still no luck.
I am using a child theme. And I do not have any code in the hooks. It’s all in functions.php. But, as I mentioned, the only code I have in that file is this snippet from you.I’m baffled. This seems like it should work. I’ll try some more things in the customization settings. Or maybe it’s a caching thing…? I tried running it on different browsers, and with incognito, and clearing the cache. Still no luck.
By the way, I’m a database programmer and have been writing code for over fifteen years, so I’m used to weird things that aren’t quite what we would call “expected behavior” =)
Best wishes,
DeniseFebruary 5, 2018 at 8:57 pm #489083Denise
Ok, I got it working. I’m not sure what fixed it, though, which is always a strange thing. My laptop had a little melt down last week and hasn’t been the same since…
You can close this ticket.
Thanks,
DeniseFebruary 5, 2018 at 11:16 pm #489113Tom
Lead DeveloperLead DeveloperGlad it’s working now 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.