I'm attempting to create "pretty" URLs for a page which takes query var input to display content. The page is called "details" and has a php script which takes the query_var idCourse and calls up specific information from the database. The reason I want to use the pretty is link is so that it can be unique for Facebook, Twitter, etc -- and the various plugins I have which seem to use the canonical link from core.

I have a rewrite that works. This is the WordPress page, with the query var request (what I call the base request):


This is the pretty request of the same page:


This is the rewrite:

add_rewrite_rule('^details/([^/]+)/?$', 'index.php?pagename=details&idCourse=$matches[1]', 'top');

As per posts here, I added a rewrite tag:

  add_rewrite_tag('%details%', '([^&]+)');

If you request the pretty URL, it successfully calls up the correct information. However, the permalink link on the page seems to be the base request and not the pretty URL. Is it possible to have the permalink (which the social sharing plugin uses) be the pretty request?

This seems to be possible based upon my other pages. I mean if you have permalinks set up, it'll show category/postname/etc. Why can't I do this?


  • What plugin are you using for canonicals? – WebElaine Apr 11 '17 at 21:45
  • You need to filter the output of get_permalink to add your extra data. – Milo Apr 12 '17 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.