6

I have a lot of clients who like to write "&" in their titles but the slug auto generation removes the "& " which can give the url a totally different meaning and so we must hand check them.

Is an override or patch or something possible to change this so that & becomes "and" ?

Title: House & Boat
e.g. http://www.domain.com/sections/house-boat
vs http://www.domain.com/sections/house-and-boat

Thanks

2 Answers 2

4

There is no easy way to override that. In the end it uses JFilterOutput::stringURLUnicodeSlug() or JFilterOutput::stringURLSafe() (depending on the global setting) to make the alias URL safe. Since & isn't a valid character in an URL it is stripped and replaced with a -.

So you had to override a core class, which isn't recommended at all.

The easier way is probably to create a plugin which runs during or after the save process and generates a new alias. I don't know if there is an existing one, but I think it should be possible to create such a plugin.

Or you can teach your users to make sure the alias is fine :-)

3
  • I believe you meant "save process" not "safe process" Apr 29, 2014 at 15:58
  • Ok Just needed the pointer to if it was possible without a core hack as could just add one line to the stringURLSafe function where it replaces spaces. Apr 29, 2014 at 15:59
  • 1
    Indeed save, not safe :)
    – Bakual
    Apr 29, 2014 at 19:10
1

Rather than teach users to monitor the alias, teach users/admins to write the titles without the ampersand to begin with. Tell them it will "break the site" if necessary, wink wink.

2
  • I have done that tactic before for file names, and other things but wanted to see a technical solution as could be possible. Apr 30, 2014 at 14:43
  • I tell them no spaces and caps in images dir and names and they still do it ! Have to have a virtual slap on the wrist button or a "No, No, NO..." Jurassic Park Gif ;) Sep 15, 2014 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.