rewrite custom taxonomy slug?
-
Hi, is there any solution for achieve this:
My url is: https://www.danielkral.cz/attachment_tag/sexy
I want: https://www.danielkral.cz/photography/tag/sexySo I want redirect “attachment_tag” to “photography/tag”???
question is simple, but 3 days online cant find a working solution nor anyone asks the same…From other topic:
Your support here seems great (plugin also), so MLA deserves to be in the core in the future WP releases I suppose with your big credits ?? Hope not only my opinion ??https://www.ads-software.com/plugins/media-library-assistant/
-
further thoughts:
I do not want create page “tag” as subpage of existing page “fotografie”. It would have an existing url with empty or some default content needed, so it make no sense to me to be clear solution even partial. Is this proper thinking?So working as you suggest here: https://www.ads-software.com/support/topic/template-query-for-att-tags?replies=7
wordpress itself allows to rename slug “tag” in the tag taxonomy (in admin menu) so Im supposing that it could be done similar on custom taxonomies. Even now, Im not sure, how much its your plugin question and how much it is question corresponding with WP matter at all.
Im not even sure now, if Im asking appropriately concerning your plugin or if I may ask generally – how to filter or hook some wordpress function od maybe directly rewrite it in htaacess (i tried but i thing its not proper way becose one of upper url does not exists- rewriting nice url to another nice url. theres no query).
found somthing about {$permastruct}_rewrite_rules in wp codex but not explained…
Now Im running like https://wordpress.stackexchange.com/questions/5413/need-help-with-add-rewrite-rule
I manualy created a page TAG with taxonomy-slug.php template but now working both urls https://www.danielkral.cz/attachment_tag/sexy
and https://www.danielkral.cz/fotografie/tag/sexy so iM facing to redirect them to second. After I will have to redirect to error page a default manuall created page “tag” which is now working https://www.danielkral.cz/photography/tag and should not be. BUt stil i feel this is not a best way how to do it… it is too awkward , isnt?
added to in htaacessRewriteRule ^attachment_tag/([^/]+)/?$ https://www.danielkral.cz/fotografie/tag/$1 [R=301,QSA,L]
but still hrefs from tag clouds targets to attachment_tag… So Im taking this as temporary solution, NOT CLEAN, anyone?consequently i found https://www.danielkral.cz/fotografie/sexy is working becose filename is “sexy” oh no… it is not sexy… grrr
(for first sample url i gave here: correct is fotografie not photography)Thanks for your interest in the plugin and for the kind words about its features and the level of support.
I am not an expert on permalinks, rewrite rules and HTACCESS, but here is a suggestion that might help you.
The
attachment_tag/sexy
portion of the URL looks like the normal way WordPress codes a request for posts and pages having the termsexy
in theattachment_tag
taxonomy. It looks like you have already created a custom template that displays a page with an[mla_gallery]
shortcode that displays the images having that term. This might be in thetaxonomy-attachment_tag.php
,taxonomy.php
orarchive.php
file. Is that right?If that is true, then you can use something like the code below to redirect the query to your desired destination:
$object = get_queried_object(); if ( isset( $object->taxonomy ) && 'attachment_tag' == $object->taxonomy ) { $term = $object->slug; wp_redirect( site_url( '/photography/tag/' . $object->slug ), 302 ); }
You can put this code just before the
get_header();
call in whatever template file is handling the original request.I know this is somewhat unconventional, but it may work for you. I’m going to mark this topic “not a support question” since it does not involve the MLA plugin directly. Please let me know if you find this helpful, if you have problems with it or if you have any further questions.
Thank you.
The code you provide unfortunatelly not works. For latter searchers I made it as:$object = get_queried_object(); if ( isset( $object->taxonomy ) && 'attachment_tag' == $object->taxonomy ) { $term = $object->slug; wp_redirect( site_url( '/fotografie/tag/' . $object->slug ), 301 );
This code directly put in taxonomy-attachment_tag.php 301 for rewrite permanently. (didnt forget visit permalinks and save even)
Using only that and created “tag” page as child in “fotografie” for prevent error 404. But still not works…
As I told before I realized that this issue is maybe not plugin question so I dont want spend your time.
Thank you for your time and I will post a solution when I google it and stick it together someway. Maybe I will stay in the solution which I supposed as temporary (as I desrcibe before). I can do that like that but its not much clean, but works… (Im not a kind of programmer even, so hope this sentence does not sounds like Im ungrateful ?? )Over this I found some strange manner with plugin: When i have some photography name only as
nt.jpg
in MLA is this picture shown as attached to abnormally count of posts. I observed that its maybe due to fact thatnt
string is appears in many posts… isnt? So maybe it should have had some other detection of placing than where string appears ??? So maybe at least this is the something which helps improve your plugin. ??EDIT: Finally working with:
A –RewriteRule ^attachment_tag/([^/]+)/?$ https://www.danielkral.cz/fotografie/tag/$1 [R=301,QSA,L]
in htaccess
B – created page TAG in FOTOGRAFIE category in admin area with using taxonomy-attachment_tag.php template.
C1 – using add_rewrite_rule as described here: need-help-with-add-rewrite-rule
C2 – with wp_redirect conditionaly rewrites url “danielkral.cz/fotografie/tag/” to 404 error page because when vistitor could reach it no tag is selected.
D – As i like reach that before I wrote, I dont know how: urls from tag cloud is still tagreting to “danielkral.cz/attachment_tag/” but its handled now with A,B,C …What could be a guide for you, to better understand what I mean is capability WP in admin area in permalinks rename slug tag for whatever.
The second, the added tag in url before “attachment_tag” I fully undernstand that is more generally thing than this plugin thing.So finally thats my temporary solution, maybe for long time, but if you in future will find a cure for make it customizable for such cases, i will be glad, but overall, great plugin !!!
And for last thing mentioned in my previous contribution here is prtscr as it seems. name of image is “nt”. https://oi39.tinypic.com/10zwak6.jpg
Thank you for the updates and for all the time you have taken to work through this issue and report your results. For a “non-programmer” you are very brave and persistent!
I regret that my suggestion was not helpful, but perhaps I did not understand your problem in all details. I am happy that you were able to find another solution.
Thank you also for reporting the problem with the where-used information for your “nt.jpg” file (“When i have some photography name only as nt.jpg in MLA is this picture shown as attached to abnormally count of posts.“) and for posting the screen image of the example. I was able to reproduce the problem in my test system, and it will be fixed in my next release.
I wish you good luck with the rest of your site development. Thanks again for your interest in the plugin and for contributing to its improvement.
Thank you. Im interested in good challenges ??
Finally I observed, how is important finalizing the forums for future someones use(hook-to-change-custom-tag-taxonomy-links) here, due to someones post, after he solve his issue, I could also have it done. So Im bringing it back in the TOTAL finaly solution in my troubles here:
There are two ways:
First I realized that name of attachment_tag taxonomy as custom taxonomy need not be renamed. Solution is create new custom taxonomy with desired name. But, now im not able to do it because I do not fully understand creating this or subsequently implement that in mla_gallery after. But its not a question for now! Thats my future chalenge.
Consequently foregoing slug fotografie (understand final “fotografie/tag” instead “attachment_tag”) is as we wrote together before more rewrite and WP issue than MLA.Second, and this is important, even if you would not cerate your own custom taxonomy with your desired name you can finaly change the url which tag cloud targetting and for this I use mentioned article, here So finally as I found solution, hope that maybe after years someone be pleased for finalizing threads as I was today.
Thank you for vishing luck and I wish you too. ??
Thank you again also for great ability to use {+variable+} in mla shorcode so I was able to do great things like using MLA as generator for multiple images in one theme on one page. Finally everything works together now on my site. (if not currently Im playing with it or improving, so visit later)
- The topic ‘rewrite custom taxonomy slug?’ is closed to new replies.