Is it possible to create a custom token from the %value% token to make it all lowercase? I created a listing attribute called City and created options of Barcelona, Madrid etc. with individual pages. Those city names start with a capital letter. I want to link to those pages from the individual listing pages, in the Page (primary) area. In the Format box for Display, I have the code:
%label% <a href="listing-city/%value%">%value</a>
The value token will give the result ‘Barcelona’ which is fine in the second instance. But for the first instance next to /listing-city/ I need the output to be barcelona, as URL’s should be in lowercase. Maybe create a new extra token called %valuelower% with strtolower. Or maybe there is another solution? I don’t think CSS can do it, as it will make the link text lowercase. Just to add that I have many listings attributes i need to do this for, not just City.
I know this is arguably outside the remit of support, but maybe it will be helpful to others, and not just me. It’s very important for SEO purposes, do I’m surprised no one else has asked.
Thanks for the reply, I appreciate it. Is there a way to do it as a hook though and use a token, like mentioned? So keep the %value% token and create another custom token that is lowercase only. I need to make the value lowercase for many listing attributes, like city, region, country as examples.
Thank you so much, that’s made my day. I’m a bit rusty with coding. Wasn’t sure if I could add the function like that with Hivepress. The only change I had to make to get it to work was to remove the quotations around the %value% because of the quotations for the URL.
I thought it was worth to mention, just in case anyone else uses this code, that if the value contains two words it will only output the first word. Not the end of the world, but it means the slug can only be the first word. So if you create an attribute called City and an option is New York, the slug can only be ‘new’. Using new-york won’t work.
/listing-city/new/
It’s better for SEO to have both in the URL. Maybe there is a solution.
Do this : <a href="listing-city/[lcase val='%value%']">%value%</a>
And actually while we are at it, I would have a put all the output in the shortcode (the text value included), instead of concatenating a lot of string chunks together.
It looks neater to me.
Something like this : [lcase val='%value%']
which would output <a href="listing-city/new-york/">New York</a>
Adding the ’ around %value% doesn’t work. It outputs the two words but without the hyphen. So it gives a URL of listing-city/new york/ so you have a space between new and york, which of course breaks the URL.
Hi again, this is normal.
If you want to add hyphens, you have to do it yourself.
That is provide an instruction and add it in the shorcode something like
$val = str_replace(" ", "-", $val);
I did not test it, but at least you get the idea.
on top (or after) of the lower case transformation.