Home > Software design >  Problems making Facebook API share link PHP Wordpress proper
Problems making Facebook API share link PHP Wordpress proper

Time:12-06

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 &quote:

const facebookApi = `https://www.facebook.com/sharer/sharer.php?u=${link}&quote=${msg}`;

const twitterApi = `https://twitter.com/intent/tweet?text=${msg}&url=${link}`;
  • Related