I am attempting to create some custom social sharing icons using Font-awesome.

I started out with the following code:

    <span>Share this article:</span>
<a class="facebook" href="https://www.facebook.com/share.php?u={{url}}&title={{title}}" target="blank"><i class="fa fa-facebook-square" aria-hidden="true"></i></a>
<a class="linkedin" href="https://www.linkedin.com/shareArticle?mini=true&url={{url}}&title={{title}}&source={{source}}" target="blank"><i class="fa fa-linkedin-square" aria-hidden="true"></i></a>
<a class="twitter" href="https://twitter.com/intent/tweet?status={{title}}+{{url}}" target="blank"><i class="fa fa-twitter-square" aria-hidden="true"></i></a>

So what I am trying to do is replace the Current Page url into the {{url}} and the current page title into the {{title}} tags.

Using the following code I can obtain the page url:

$uri = JUri::getInstance();

But when trying to insert this into just the {{url}} part as below it breaks on the {{title}}.

<a class="facebook" href="https://www.facebook.com/share.php?u="<?php echo $uri ?>"title={{title}}" target="blank"><i class="fa fa-facebook-square" aria-hidden="true"></i></a>

Can anyone possibly advise the best way to do this so that it remains dynamic to share the current page?

  • 2
    Hi Dtorr: Is this a module or plugin, or you write this in the article's body? I also see syntax errors In your code snipped above. You start wrapping the href attribute with the double quotes and you are closing them before you open the <?php tags to echo the $uri ... and so on. So first of all you have to make sure you are using correct syntax. (This type of syntax errors questions are off-topic in JSE). Then I would advise to consult the FB API Docs and the other Social media's API for how you can use their sharer features. – FFrewin May 16 at 7:54
  • @Dtorr Please progress this question toward a resolution. If my answer doesn't solve your issue I am happy to delete it or adjust it. Please help us to help you. – mickmackusa May 25 at 3:18

You have misplaced quotes around PHP tags and missing the ampersand (&) before the title.

<a class="facebook" href="https://www.facebook.com/share.php?u=<?php echo $uri ?>&title={{title}}" target="blank"><i class="fa fa-facebook-square" aria-hidden="true"></i></a>

Also you should run the variables used in URL through urlencode().

Your Answer

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

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