Struggeling with the same issue, but it’s still not working with the code snippet from above on my site. It’s still using /tag/ for category links instead of the correct category base slug, maybe it needs to get replaced anywhere else also?
Hello @cloutsca,
that’s interesting and it means that – because it works in your case – that there can be a situation when is_category or is_tag needs explicitly the ID of the queried object.
@mattce is_category( $id ) should work for a category. It would mean that the WordPress API is not working here, what seems less probable. Please, describe your setup.
Cheers,
Dennis
@dennis I’ve uploaded my steps on imgur: https://imgur.com/a/NGvu1l8
I’m working with a standard archive.php without any further special rules or something, so there should not occur any conflicts with the theme itself.
One other thing I noticed…
I first was using category and tag slugs composed of multiple tokens.
On french site/blog:
Post slug was: /publications/%postname%/
Category slug was: publications/categories
Tag slug was: publications/etiquettes
On english site/blog:
Post slug was: /posts/%postname%/
Category slug was: posts/categories
Tag slug was: posts/tags
Even with the change I made (detailed in a comment above), problem was still occuring. So I revert back to use a single token slug for category and tag.
On french site/blog:
Post slug was: /publications/%postname%/
Category slug was: categories-de-publication
Tag slug was: etiquettes-de-publication
On english site/blog:
Post slug was: /posts/%postname%/
Category slug was: post-categories
Tag slug was: post-tags
Problem was then solved with the solution I proposed (detailed in a comment above). But something else should probably need a fix here.
Or maybe the conflict only occured because I was using the same slug start as for posts? I don’t know
-
This reply was modified 7 years, 4 months ago by
cloutsca.
Wow ok… I don’t know what is going on now…
I am pretty sure that my proposed fix was working late last night! :O
Tested it again this morning and it seems that the problem occurs again.
I am using twentyseventeen theme.
Hmmm … strange @cloutsca. Did you always a refresh of the permalinks (visiting the section in the admin)?
@mattce The interesting var is $req because the plugin decides with its value what class to call.
@all You don’t have any custom code in place?
@dennis var_dump($req) outputs: “post_tag”, so the problems seems to be in the line
$req = is_category($id) ? 'category' : is_tag($id) ? 'post_tag' : '';
If I set $req manually to “category”, all links are working properly.
var_dump(is_category()) delivers bool(true) also ( whereas var_dump(is_tag()) delivers bool(false) ).
So it’s mistakenly setting post_tag in the line from above.
-
This reply was modified 7 years, 4 months ago by
mattce.
Ok now I got it… I think.
It has nothing to do with putting the $id or not in the is_category or is_tag function.
Just enclose the 2 ternary statements like this:
$req = (is_category() ? 'category' : (is_tag() ? 'post_tag' : ''));
I probably did this the first time to fix it but conclude to the wrong fix.
Ok, thanks! Nice catch, version 2.1.1 is on the way…
Thank you both, works like a charm 🙂