WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to use the_permalink() in order to construct a simple link from each post . the link should be like


I use ?output=something" >

the problem is that the trailing slash of the permalink is giving me an extar trailing slash that is breaking my link .


I know that I can construct the structure in another way , but I want to use the permalink (much easier) and i do not want to change the permalink structure sitewide ...

any way of getting rid of the trailing slash ??

share|improve this question
up vote 1 down vote accepted

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.

share|improve this answer
echo substr(the_permalink(), 0, -1);
share|improve this answer
+1 to exit .. yep - I answered fast , but I believe that EXIT is right - better rtrim.... – krembo99 Jan 5 '12 at 12:45

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.