I have created a custom plugin that adds a rewrite rule so that a url like this http://domain.com/listings/property/123456 will resolve to the page 'listings'. That works great. I also have removed the default WordPress canonical url and added my own to match the rewrite rule so then on that page the canonical url shows like

<link rel='canonical' href='http://domain.com/listings/property/123456' />

However when a social sharing plugin like AddToAny is installed and shows on that page, it doesn't grab the full url for sharing - instead just grabs the url of the WordPress page itself -- http://domain.com/listings

When I look at what they are doing in the code for that plugin they are making a call to get_permalink() for the page and using that for sharing.

Any ideas on ways to overcome this? I don't think dynamically setting the permalink will solve the problem - that would probably break the original rewrite rule. Perhaps there is another WordPress action that would be helpful?

  • What is a property exactly? Where does that data come from? I don't see how filtering the output of get_permalink would break a rewrite rule, what is the logic behind that? – Milo Dec 9 '16 at 17:38
  • Thanks for the response! Here is what the rewrite rule does. domain.com/listings/property/123456 --> domain.com/listings/?property=123456. Even if I use the second example, passing a variable called property to the page (and not use a rewrite rule), the social sharing plugins will strip off the variable at the end and just try and share "domain.com/listings". I want to somehow prevent that stripping from happening. – sceilig Dec 9 '16 at 19:27
  • Filtering the output of get_permalink seems appropriate in this case. – Milo Dec 9 '16 at 22:09
  • Thank you @Milo for your help with this. Yes, I do need to somehow filter the output of get_permalink. However my attempts at doing that have been unsuccessful. I have tried this where I add a test parameter to the permalink. function append_query_string($url, $post) { $url = add_query_arg("param","value", $url); return $url; } add_filter('post_type_link', 'append_query_string', 10,2); but that doesn't work. When I output get_the_permalink() afterwards it still has the original permalink, without the parameter added. – sceilig Jan 9 '17 at 18:58
  • Sorry - can't seem to get a block of code to display correctly in a comment. – sceilig Jan 9 '17 at 18:59

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.