I am trying to create a Facebook share button to a Wordpress website. It works, but it does not work properly like I would. When sharing it to Facebook, it does not share the article. It says only "page not found", and the link does not work, and the message does not come along when sharing.
This is the code I am working with in PHP:
const facebook = document.querySelector('.facebook');
const twitter = document.querySelector('.twitter');
const telegram = document.querySelector('.telegram');
const msg = ('Hey, pls share this article on...');
const link = location.href;
const facebookApi = `https://www.facebook.com/sharer/sharer.php?u=${link}. ${msg}`;
const twitterApi = `https://twitter.com/intent/tweet?text=${msg}. ${link}`;
const telegramApi = `https://t.me/share/url?url=${msg}&text=${link}`;
Twitter and Telegram works perfect with this code. But not Facebook.
Does anybody what is wrong here with the share link to Facebook?
CodePudding user response:
You are missing part of the code for FB (and for Twitter), try adding the second URL parameter "e
:
const facebookApi = `https://www.facebook.com/sharer/sharer.php?u=${link}"e=${msg}`;
const twitterApi = `https://twitter.com/intent/tweet?text=${msg}&url=${link}`;