you create a variable called $RoutName which is the string without spaces, but then you echo the original $RouteName, not the copy without the spaces? Also there’s no semi-colon after the echo(), shouldn’t that throw an error message? (Note, I know nothing about Wordpress).
Well, I’m very new to php. I’m trying to figure this out get the return value of the advanced customs field function <?php the_sub_field('route_name')?> then remove all spaces from that string and echo the new value of the variable $RoutName with the spaces of the string removed.
Key thing in either is that you’re creating a new variable called $RoutName, which is a copy of $RouteName but passed through whatever function you choose to remove spaces. So you then have to echo that variable, not the original, or you’ll still get the spaces.
Try taking the php script outside of the unordered list and introducing two additional list items. Also renaming $RoutName to $uriName to avoid confusion.
First list item is ‘XXX’ .$RouteName .‘XXX’ second list item is ‘YYY’ .$uriName .‘YYY’
We’re going to need a bit more information then. When you say “neither works”, what exactly happens? Do you get error messages, the wrong link text, no link text? To start with, what’s in $RouteName and what’s in $RoutName? And can you show more of the code, a few extra lines to show your query, and the start and end of the loop that builds the list?
I believe that there is an error in this code, but I don’t know where. Dreamweaver is coloring the line of code red, but I can’t seem to find the error.
If the word of someone on StackOverflow is correct, the above function will print the data field you requested, which would explain why it doesn’t matter what you do to it, and would explain your comment in #3 that it still outputs even if you remove the code that echoes it.
The same poster suggests using get_sub_field() instead, which returns it as a string (what you want to do) rather than just displaying it.