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 am filtering the_permalink to return a custom structure

 function append_query_string($url) {
$url_endpoint = get_permalink();
$url_endpoint = parse_url( $url_endpoint );
$url_endpoint = $url_endpoint['path']; 
return '#!'. $url_endpoint;
 add_filter('the_permalink', 'append_query_string');

the filter above returns


I need to remove the leading #! form that url and I had tried using get_permalink but I have found that the filter does not filter get_pemalink. I have checked the codex and I cannot find a filter for get_permalink. Do you know of a way to filter it so that it will match the_permalink? I can't use the_permalink because it outputs the information to the screen and breaks layout. I can't seem to assign it to a variable either.

share|improve this question
up vote 3 down vote accepted

If we look at get_permalink in source, we'll see the various filters applied to this function.

For posts, it's post_link, for custom post types, it's post_type_link, for pages it's page_link, and attachments is attachment_link.

share|improve this answer
I tried post_link and got a bunch of errors. I change the filter above from the_permalink to post_link and got these errors: fatal error: Maximum function nesting level of '100' reached, aborting! – Jamie Jan 13 '13 at 19:24
You're calling the function you're filtering within the filter, so you enter a never-ending loop. the value is already passed to the function via the $url argument, no need to get the permalink within the function. – Milo Jan 13 '13 at 19:26
I see. Thank you. I think I got it sorted. checking the source was a good idea. I see lots of stuff in there to play with – Jamie Jan 13 '13 at 19:35

Your Answer


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

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