How to remove the last slash from the url with params in wordpress

I’d like to remove the last slash from the url with params in wordpress. For example: http://localhost/autoservice/?param=1 -> http://localhost/autoservice?param=1

Answer

You can use the trim command to do this, specifically, the rtrim to remove the character from the right side:

$url = rtrim(get_permalink(),'/');

Using a blanket substr -1 technique would cause problems if there isn’t a trailing slash in the permalink. Also, the function the_permalink echoes the link, and get_permalink returns it as a string.