0

)

I found (for example in Set default (auto) slug prefix for Tags) that it is possible for example add my-taxonomy prefix in front of all taxonomy slugs (permalinks). The post is outdated now since such prefix can be now specified in WP settings.

What can't be done in settings it to specify slug prefix (=> modify slug) for a specific/custom post type. There are some plugins that can do that but they usually do a lot of things and I'd prefer to write a couple of lines of code that I can add to functions.php/custom plugin/mu-plugin...

In other words I'm trying to write PHP that gets fired just after a post (with defined type) is created and that alters slug from my-new-post to my-prefix/my-new-post.

I spent two days of googling / testing but I haven't been able to make it work. At least not for post_type attachment.

Could you please help me with that?

Thank you.

Best regards,

Mat

  • The question you linked to is for tags, not posts. Is there a reason you're asking speciifically about filters just after save? If the goal is to turn yoursite.com/slug into yoursite.com/prefix/slug then why not ask about that? There may be better solutions that have nothing to do with filtering just after post saves, especially if you want this for a CPT. What problem does adding the prefix solve for you? – Tom J Nowell Aug 10 at 15:02
  • Hi Tom, Yes, the goal is to automatically adjust links from mysite.com/photo-of-my-car to mysite.com/attachments/photo-of-my-car since the attachment/media pages are using non-prefixed URLs that I'd like to dedicate for actual blog posts, not images... And yes, you're right. I should ask a general question "how to do X" instead of asking "how to code X". Thank you ;-) – Mat Ej Aug 11 at 6:45
  • Ah then you should ask how to prefix attachment permalinks with attachment, it's a much simpler question, easier to understand, easier to answer. If your proposed solution got an answer you would still need to re-save every attachment to apply the new permalink, which is not the case with a generic permalink adjustment – Tom J Nowell Aug 11 at 8:33
  • Thank you! I've just posted the new question: wordpress.stackexchange.com/questions/372803/… – Mat Ej Aug 11 at 14:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.