Question

The Problem:

First of all my site is using WordPress. I am using the facebook sharer on lots of links that include a # or fragment identifier in the URL. The problem with that is the facebook sharer doesn't allow this and stops the link.

For example if my link is: example.com/europe/#comment-123

The facebook sharer will change this to: example.com/europe

I have been able to change it so the facebook sharer URL will display it as the following: example.com/europe/123 This was achieved using this code within the "[url]=" part of the facebook sharer code:

<?php echo esc_url ( get_permalink()); ?><?php comment_ID(); ?>

One way I have tried to solve this problem is by trying to echo the "#comment-" using this code:

<?php echo esc_url ( get_permalink()); ?><?php echo "#comment-" ?><?php comment_ID(); ?>

But once again the facebook sharer stops this displaying.

Desired Solutions:

1) If anyone knows any code that will allow the facebook sharer to hyperlink the fragment identifier

2) I read elsewhere a possible solution would be to do a redirect. So if I can get the facebook sharer to display a url of example.com/europe/123 and can redirect that to example.com/europe/#comment-123 then it would be fine. I would need this to happen on all comments, so no matter what the page, whether for example it be europe asia or africa, whenever anyone follows that with a number if automatically puts "#comment-" before the number

However, if I have several pages in the form of example.com/europe example.com/asia etc etc I'd imagine this would be become more difficult.

Was it helpful?

Solution

have you tried urlencode()

urlencode('example.com/europe/#comment-123');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top